docker - 构建过程中的命令和shell中的命令之间的区别
问题描述
我有这样的Dockerfile
:
FROM ruby:2.5
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
RUN apt-get install imagemagick libmagickcore-dev libmagickwand-dev
RUN gem install bundle
RUN mkdir /app
WORKDIR /app
COPY Gemfile /app/Gemfile
COPY Gemfile.lock /app/Gemfile.lock
COPY . /app
RUN bundle install
和docker-compose.yml
version: '3.3'
services:
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/app
ports:
- "3000:3000"
depends_on:
- db
volumes:
db_data:
我正在进入容器并运行bundle install
命令:
docker-compose run web bundle install
它没有错误:
...
Bundle complete! 28 Gemfile dependencies, 98 gems now installed.
Bundled gems are installed into `/usr/local/bundle`
但是当我构建容器时,它会产生一些错误:
docker-compose build web
Bundler could not find compatible versions for gem "activemodel":
In snapshot (Gemfile.lock):
activemodel (= 5.2.1)
In Gemfile:
activeresource was resolved to 5.0.0, which depends on
activemodel-serializers-xml (~> 1.0) was resolved to 1.0.2, which depends
on
activemodel (> 5.x)
activeresource was resolved to 5.0.0, which depends on
activemodel (< 6, >= 5.0)
carrierwave was resolved to 1.2.3, which depends on
activemodel (>= 4.0.0)
protected_attributes was resolved to 1.0.2, which depends on
activemodel (< 5.0, >= 4.0.0.beta)
rails (= 5.2.1) was resolved to 5.2.1, which depends on
activemodel (= 5.2.1)
Running `bundle update` will rebuild your snapshot from scratch, using only
the gems in your Gemfile, which may resolve the conflict.
ERROR: Service 'web' failed to build: The command '/bin/sh -c bundle install' returned a non-zero code: 6
我试图了解这些环境之间的区别(?):构建过程和外壳,但命令bundle install
是相同的。
为什么构建过程会产生错误?
附言
docker image list docker●[ruby-2.5.1p57]
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 6f5884e6a480 2 minutes ago 987MB
dev_web latest 44c878bad0f2 About an hour ago 1.21GB
<none> <none> ca720e782976 3 hours ago 1.21GB
ruby 2.5 34d1c6024e99 37 hours ago 869MB
docker ps -a docker●[ruby-2.5.1p57]
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bbd1c5dfd92b 6f5884e6a480 "/bin/sh -c 'bundle …" 55 seconds ago Exited (6) 39 seconds ago elated_meitner
解决方案
差异源于您要映射的卷docker-compose.yaml
。它会覆盖您的最后四个步骤Dockerfile
。具体来说,您似乎有不同Gemfile
的构建容器和运行容器。
如果您跳过安装卷,则在尝试install
在正在运行的容器中时应该会遇到相同的错误。
推荐阅读
- java - 使用限定符注入类时如何在单元测试中使用不同的实现
- python - Spark 在正在进行的 Spark 应用程序中将 RDD 和 Spark 数据帧存储在哪里
- botframework - 如何使用移动视图处理自适应卡片
- javascript - 将整个 Nodejs 全栈应用程序编译为 android 应用程序
- pentaho - 在 Spoon (PDI) 中安排的作业不会停止在 Pentaho Server (CE) 中运行
- python - 我有一个问题。如何遍历 for 并将数据添加到列表中?
- python - 根据一个值在多个列表中列出的次数创建新列表
- regex - 如何为 Sitescope 日志监视器日志文件路径创建正则表达式?
- python - 有没有办法使变量等于两个 if 语句?
- python - 为什么不以不正确的方式为字典赋值是错误的?