【问题标题】:Unable to run rails console using Docker Compose无法使用 Docker Compose 运行 Rails 控制台
【发布时间】:2016-06-23 21:54:44
【问题描述】:

我对 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 以安装缺少的 gem。

我尝试做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

docker-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

【问题讨论】:

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


    【解决方案1】:

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

    docker-compose exec web rails console
    

    【讨论】:

    • 这绝对正确!如果@joes 将其标记为正确的解决方案,那就太好了。
    • 完美的答案对我有用。请将此标记为正确;)
    【解决方案2】:

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

    docker ps
    

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

    docker exec -ti 916703608c5e rails console production
    

    【讨论】:

    • 这是不正确的。您当然可以使用 docker-compose 为其设置的服务运行命令。
    • @x1a4 这很有趣——那么你能给出正确答案吗?
    • 我的意思是,如果还有 docker-compose 函数也很酷,但只要我们谈论的是非 docker-compose 函数,我发现做上述工作,除了代替 gitlab-导轨,我只是使用导轨。你在使用某种特定于 gitlab 的 rails 版本吗?
    • @MikeBelanger:哎呀,是的,我是。谢谢,我编辑了帖子以删除它
    【解决方案3】:

    首先,尝试使用以下命令重建图像:

    docker-compose build web
    

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

    再试一次:

    docker-compose run web rails console
    

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

    docker-compose run web sh
    

    然后运行:

    rails console
    

    【讨论】:

      【解决方案4】:
      $ 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

      【讨论】:

        【解决方案5】:

        派对迟到了,但以上内容对我不起作用。我收到以下错误:

        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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-02-13
          • 1970-01-01
          • 1970-01-01
          • 2021-07-06
          • 1970-01-01
          • 2022-09-05
          • 2017-06-23
          • 1970-01-01
          相关资源
          最近更新 更多