Ruby 捆扎机锁定在docker+;can';t安装gems(已解决-docker CMD vs ENTRYPOINT)
更新:我已将[或?]问题缩小到我的Ruby 捆扎机锁定在docker+;can';t安装gems(已解决-docker CMD vs ENTRYPOINT),ruby,docker,rubygems,bundler,Ruby,Docker,Rubygems,Bundler,更新:我已将[或?]问题缩小到我的服务:app:volumes字典中的-groupy-gemcache:/usr/local/bundle行。如果我删除它,容器运行正常[我认为],但我可能会丢失本地gem缓存 tldr:在运行docker compose build之后,事情似乎还可以,但是如果我向gemfile中添加了一些内容,我就不能在我正在运行的docker容器中运行任何gem或bundle。例如,在docker compose构建和&docker compose运行应用程序bash之后:
服务:app:volumes
字典中的-groupy-gemcache:/usr/local/bundle
行。如果我删除它,容器运行正常[我认为],但我可能会丢失本地gem缓存
tldr:在运行docker compose build之后,事情似乎还可以,但是如果我向gemfile中添加了一些内容,我就不能在我正在运行的docker容器中运行任何gem
或bundle
。例如,在docker compose构建和&docker compose运行应用程序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的新手,但我一直在尝试配置一个完美的dockerfile,它可以构建、缓存gems和更新,同时仍然将Gemfile.lock提交给git[也许这并不完美,我愿意接受那里的建议]。在我的使用案例中,我使用了一个docker compose文件,其中包含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"]
docker-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命令,如本章末尾所述
我相信
ENTRYPOINT[“bundle”,“exec”]
与CMD[“/script/start.sh”]的结果
或docker compose run应用程序bash
将运行类似于bundle exec'bash'
的命令。我确认了这一点,从dockerfile中删除入口点,如上所述进入shell并手动运行bundle exec'bash'
,果然我进入了一个无法运行任何bundle或gem命令的子shell退出两次,然后离开。非常高兴您发布了此消息,我收到了相同的错误消息,并从ENTRYPOINT切换到CMD,使docker compose运行web bundle安装work