docker - 如何使“docker build”从上次失败的地方开始
问题描述
我是码头工人的新手。我正在尝试创建一个运行以下命令:
docker build .
下面是我的 Dockerfile:
# gets the docker image of ruby 2.5 and lets us build on top of that
FROM ruby:2.3.1-slim
RUN uname --kernel-name --kernel-release --machine
RUN cat /etc/os-release
# W: There is no public key available for the following key IDs: AA8E81B4331F7F50
# RUN apt-get install -y debian-archive-keyring
# RUN apt-key update
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys AA8E81B4331F7F50
# install rails dependencies
RUN apt-get update && apt-get upgrade
RUN apt-get install -y curl
RUN apt-get install -y build-essential libpq-dev git-core zlib1g-dev libreadline-dev libyaml-dev libxml2-dev
RUN apt-get install -y libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev curl
RUN echo "Curl version:"
RUN curl --version
RUN curl -o- -L https://deb.nodesource.com/setup_12.x | bash -
# Install Yarn from script
RUN curl -o- -L https://yarnpkg.com/install.sh | bash -
RUN echo "Yarn install version"
RUN yarn --version
# RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 8B48AD6246925553
# create a folder /myapp in the docker container and go into that folder
RUN mkdir /avocado
WORKDIR /avocado
# Copy the Gemfile and Gemfile.lock from app root directory into the /avocado/ folder in the docker container
COPY Gemfile /avocado/Gemfile
COPY Gemfile.lock /avocado/Gemfile.lock
# Run bundle install to install gems inside the gemfile
RUN bundle install
# Copy the whole app
COPY . /avocado
例如,docker 脚本失败:
RUN curl -o- -L https://deb.nodesource.com/setup_12.x | bash -
由于某些原因,然后更改了脚本并运行docker build 。再次,但是 Docker 从头开始。这对我来说非常不方便和耗时。为了达到失败的地步,我必须等待近 4GB 的存储空间被重做,并且在我知道我的更改工作与否之前需要大约 1000 万。
如果它可以从失败的地方继续运行,例如这条线,那就太好了
RUN curl -o- -L https://deb.nodesource.com/setup_12.x | bash -
我想知道如何实现这一目标?或者你有什么更好的方法来克服这个问题?
解决方案
docker build 只缓存那些成功构建的层并从下一个失败的层开始,除非你明确地--no-cache
通过@linpy 提到的。所以在你的情况下
# Install Yarn from script
RUN curl -o- -L https://yarnpkg.com/install.sh | bash -
RUN echo "Yarn install version"
RUN yarn --version
.
.
.
在上述情况下,如果它在 curl 中失败,那么它将从 curl 的下一个构建开始,然后构建该层的其余部分。
解决方法:
- 如果下一层不依赖于此,则将这些行移动到泊坞窗的末尾。
RUN curl -o- -L https://yarnpkg.com/install.sh | bash -
推荐阅读
- android - 调用其他活动方法时显示 NullPointerException
- mongodb - mongodb有模式吗
- r - 如何在 R 中为变量中的不同级别生成图
- c# - Asp.Net core/Razor Pages 奇怪的会话行为:会话每秒被丢弃一次
- mysql - 两个如何根据其中一个中的最高值加入表?
- java - 每个对象的 Libgdx 不同的输入侦听器
- angular - ng build --watch : modules[moduleId] 未定义
- r - 无法在没有 R 出现致命错误的情况下绘制聚类分析
- python - 使用 Python 并行处理图像的分割和连接
- python-3.x - 以有效的方式绘制具有相同 X 轴的多条线