无法使用Docker Compose

时间:2016-06-23 21:54:44

标签: ruby-on-rails ruby-on-rails-4 docker docker-compose

我是Docker的新手,并开始使用Docker Compose在我的OS X 10.10机器上开发我的rails 4应用程序。 rails应用程序工作正常,但如果我尝试使用以下命令运行rails控制台:

docker-compose run web bundle exec rails console

docker-compose run web rails console

我收到以下错误:

  

无法在任何来源中找到CFPropertyList-2.3.1运行bundle install以安装缺少的宝石。

我尝试了docker-compose run web bundle install,但我仍然遇到同样的错误。这背后的原因是什么?下面是我的Dockerfile和docker-compose.yml。

Dockerfile

FROM ruby:2.2.0

RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs npm nodejs-legacy
RUN npm install -g phantomjs

RUN mkdir /myapp
WORKDIR /myapp

ADD Gemfile /myapp/Gemfile
ADD Gemfile.lock /myapp/Gemfile.lock

RUN bundle install
ADD . /myapp

搬运工-compose.yml

version: '2'
services:
  db:
    image: postgres
  mailcatcher:
    image: yappabe/mailcatcher
    ports:
      - "1025:1025"
      - "1080:1080"
  web:
    build: .
    command: bundle exec rails s -p 3000 -b '0.0.0.0'
    volumes:
      - .:/myapp
    ports:
      - "3000:3000"
    links:
      - db
      - mailcatcher

5 个答案:

答案 0 :(得分:18)

您必须在根文件夹中使用:

docker-compose exec web rails console

答案 1 :(得分:5)

要访问rails控制台,您需要docker命令,而不是docker-compose。 第一次运行

docker ps

找到CONTAINER ID(例如916703608c5e),然后用该容器ID运行docker exec:

docker exec -ti 916703608c5e rails console production

答案 2 :(得分:1)

首先,尝试使用以下方法重建图像:

docker-compose build web

或者 如果它不起作用,则强制执行:docker-compose build web --no-cache

再试一次:

docker-compose run web rails console

如果这不起作用,您可以随时使用shell:

docker-compose run web sh

然后运行:

rails console

答案 3 :(得分:0)

该党迟到了,但是以上情况对我没有用。我收到以下错误:

Error response from daemon: OCI runtime create failed: container_linux.go:346: starting container process caused "exec: \"rails\": executable file not found in $PATH": unknown

但是以下内容为我解决了这个问题:

docker-compose exec <container> bundle exec rails console

答案 4 :(得分:0)

$ docker-compose exec web rails console
OCI runtime exec failed: exec failed: container_linux.go:349: starting container process caused "exec: \"rails\": executable file not found in $PATH": unknown


$ docker-compose exec web bundle exec rails console    
Loading development environment (Rails 6.0.2.2)
irb(main):001:0> 

解决方案

$ docker-compose exec web rails console

docker-compose exec web bundle exec rails console