docker+中的Bundlerlocking不能安装gem(Solved-docker CMD vs ENTRYPOINT)

更新:我已经把[或者]问题缩小到我的services: app: volumes字典中的行- groupy-gemcache:/usr/local/bundle 。 如果我删除它,容器运行良好[我认为],但可能是我失去了我当地的gemcaching。

tldr:在运行docker-compose build之后,事情似乎没有问题,但是如果我在gemfile中添加了一些东西,我不能在运行的docker容器中运行任何 gembundle 。 例如,在docker-compose build && docker-compose run app bash

 root@2ea58aff612e:/src# bundle check The Gemfile's dependencies are satisfied root@2ea58aff612e:/src# echo 'gem "hello-world"' >> Gemfile root@2ea58aff612e:/src# bundle Could not find gem 'hello-world' in any of the gem sources listed in your Gemfile. Run `bundle install` to install missing gems. root@2ea58aff612e:/src# bundle install Could not find gem 'hello-world' in any of the gem sources listed in your Gemfile. Run `bundle install` to install missing gems. root@2ea58aff612e:/src# gem Could not find gem 'hello-world' in any of the gem sources listed in your Gemfile. Run `bundle install` to install missing gems. root@2ea58aff612e:/src# gem env Could not find gem 'hello-world' in any of the gem sources listed in your Gemfile. Run `bundle install` to install missing gems. 

我仍然是与docker相当新手,但我一直在试图configuration一个完美的docker文件,可以build立,cachinggem和更新,同时仍然提交它的Gemfile.lock git [也许这并不完美,我打开到那里的build议]。 在我的使用案例中,我正在使用一个docker撰写文件,其中包含一个rails应用程序和sidekiq worker的图像以及postgres和redis图像 – 非常类似于这里和这里描述的设置。

我的Dockerfile [有些事情我注意到,我从上面的教程拼凑:

  FROM ruby:2.3 ENTRYPOINT ["bundle", "exec"] ARG bundle_path # throw errors if Gemfile has been modified since Gemfile.lock # RUN bundle config --global frozen 1 ENV INSTALL_PATH /src RUN mkdir -p $INSTALL_PATH WORKDIR $INSTALL_PATH # Install dependencies: # - build-essential: To ensure certain gems can be compiled # - nodejs: Compile assets # - npm: Install node modules # - libpq-dev: Communicate with postgres through the postgres gem # - postgresql-client-9.4: In case you want to talk directly to postgres RUN apt-get update && apt-get install -qq -y build-essential nodejs npm libpq-dev postgresql-client-9.4 --fix-missing --no-install-recommends && \ rm -rf /var/lib/apt/lists/* COPY app/Gemfile app/Gemfile.lock ./ # Bundle and then save the updated Gemfile.lock in our volume since it will be clobbered in the next step RUN echo $bundle_path && bundle install --path=$bundle_path && \ cp Gemfile.lock $bundle_path # ./app contains the rails app on host COPY app . # Unclobber the updated gemfile.lock RUN mv $bundle_path/Gemfile.lock ./ CMD ["./script/start.sh"] 

泊坞窗,compose.yml:

 version: '2' volumes: groupy-redis: groupy-postgres: groupy-gemcache: services: app: build: args: bundle_path: /usr/local/bundle context: . dockerfile: Dockerfile command: "./script/start.sh" links: - postgres - redis volumes: - ./app:/src - groupy-gemcache:/usr/local/bundle ports: - '3000:3000' env_file: - .docker.env stdin_open: true tty: true 

哇,我知道了。 这个问题来自我的ENTRYPOINT dockerfile命令,正如本文关于CMD vs ENTRYPOINT的结尾所解释的那样 。

我相信使用CMD ["./script/start.sh"]docker-compose run app bashENTRYPOINT ["bundle", "exec"]结果就是运行一个像bundle exec 'bash'这样的命令。 我确认了这一点,从dockerfile中删除入口点,像上面那样进入shell并手动运行bundle exec 'bash' exec'bash bundle exec 'bash' ,果然我登陆了一个我无法运行任何bundle或者gem命令的子shell,只好exit两次离开。