nginx镜像来运行rails控制台

nginx镜像来运行rails控制台

本文介绍了我无法使用Docker和Passenger / nginx镜像来运行rails控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下一个docker-compose容器:

I've the next docker-compose container:

# docker-compose.yml
version: '2'
services:
 web:
  build: .
  ports:
    - "80:80"
  volumes:
    - .:/home/app/NAME_OF_MY_APP
 db:
  image: postgres:9.4
  ports:
    - "5432"
  environment:
    POSTGRES_USER: 'postgres'

我不知道如何运行rails控制台。我正在使用乘客/ nginx镜像,一切正常。
但是,我的数据库是在另一个容器,我想在rails控制台进入手动创建几个用户。

I cannot figure out how can I run the rails console. I'm using the passenger/nginx image and everything is working.However, my DB is on another container and I'd like to entry at rails console to create manually a couple of users.

我试过: / p>

I tried with:

sudo docker-compose run web rails c

但是出现下一个错误:

ERROR: Cannot start service web: oci runtime error: exec: "rails": executable file not found in $PATH

另外,我尝试: / p>

Also, I tried:

sudo docker-compose run web "rails c"

但它仍然显示相同的输出。

But it stills showing the same output.

我想在控制台输入,输入一些用户并存储在postgres DB上。

I'd like to entry at console, entry some users and store it on the postgres DB.

提前感谢

推荐答案

使用 docker-compos up 组合容器,它会启动所有定义的服务。然后,您可以按名称附加到运行中的容器。您从 docker ps 的输出中获取运行容器的名称,例如:

First you have to start your composed containers with docker-compose up, which starts all of your defined services. Then you can attach to your running containers by their name. You get the names of running containers from the output of docker ps, e.g.:

CONTAINER ID        IMAGE       COMMAND  CREATED        STATUS              PORTS                    NAMES
d6b317a4c10b        image       "..."    27 hours ago   Up 27 hours         0.0.0.0:4284->4284/tcp   container1
4fe15ab206b5        postgresql  "..."    27 hours ago   Up 27 hours         5432/tcp                 container2

所以在这个例子中,container2是我的数据库。但我想连接到我的Web应用程序。所以我可以在运行容器中直接启动一个shell:

So in this example container2 is my database. But I want to connect to my web application. So I can directly start a shell in the running container:

docker exec -it container1 bash

它启动container1内的bash。从那里你可以运行你喜欢的任何命令,例如你的导轨控制台。

which starts a bash inside container1. From there you can run any command you like, e.g. your rails console.

另外你,因为版本1缺少一些功能。

Also you should use version 2 of docker-compose files, since version 1 lacks of some features.

这篇关于我无法使用Docker和Passenger / nginx镜像来运行rails控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 19:53