Bundler 锁定在 docker + 无法安装 gems(已解决 - docker CMD vs ENTRYPOINT)
Bundler locks in docker + can't install gems (Solved- docker CMD vs ENTRYPOINT)
更新:我已将 [or a?] 问题缩小到 services: app: volumes
词典中的 - groupy-gemcache:/usr/local/bundle
行。如果我删除它,容器 运行 没问题 [我认为] 但大概我丢失了我的本地 gem 缓存。
tldr:在 运行ning docker-compose 构建之后,一切似乎都正常,但我不能 运行 any gem
或 bundle
在我的 运行ning docker 容器中,如果我向我的 gem 文件添加内容。例如,在 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 的新手,但我一直在尝试配置一个完美的 docker 文件,它可以构建、缓存 gem 和更新,同时仍然提交它的 Gemfile.lock 到 git [也许这实际上并不完美,我愿意接受那里的建议]。在我的用例中,我使用 docker 包含图像的 rails 应用程序和 sidekiq worker 以及 postgres 和 redis 图像的组合文件 - 与 here and here 描述的设置非常相似。
我的 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 命令,如 this article on CMD vs ENTRYPOINT.
末尾所述
我相信 ENTRYPOINT ["bundle", "exec"]
与 CMD ["./script/start.sh"]
或 docker-compose run app bash
的结果是 运行 像 bundle exec 'bash'
这样的命令。我通过从 dockerfile 中删除入口点,如上所述输入 shell 并手动 运行ning bundle exec 'bash'
来确认这一点,果然我降落在我不能的 subshell t 运行 任何捆绑包或 gem 命令 - 必须 exit
两次才能离开。
更新:我已将 [or a?] 问题缩小到 services: app: volumes
词典中的 - groupy-gemcache:/usr/local/bundle
行。如果我删除它,容器 运行 没问题 [我认为] 但大概我丢失了我的本地 gem 缓存。
tldr:在 运行ning docker-compose 构建之后,一切似乎都正常,但我不能 运行 any gem
或 bundle
在我的 运行ning docker 容器中,如果我向我的 gem 文件添加内容。例如,在 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 的新手,但我一直在尝试配置一个完美的 docker 文件,它可以构建、缓存 gem 和更新,同时仍然提交它的 Gemfile.lock 到 git [也许这实际上并不完美,我愿意接受那里的建议]。在我的用例中,我使用 docker 包含图像的 rails 应用程序和 sidekiq worker 以及 postgres 和 redis 图像的组合文件 - 与 here and here 描述的设置非常相似。
我的 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 命令,如 this article on CMD vs ENTRYPOINT.
末尾所述我相信 ENTRYPOINT ["bundle", "exec"]
与 CMD ["./script/start.sh"]
或 docker-compose run app bash
的结果是 运行 像 bundle exec 'bash'
这样的命令。我通过从 dockerfile 中删除入口点,如上所述输入 shell 并手动 运行ning bundle exec 'bash'
来确认这一点,果然我降落在我不能的 subshell t 运行 任何捆绑包或 gem 命令 - 必须 exit
两次才能离开。