我是Docker的新手。我试图创建一个运行以下命令:
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从头开始。这对我来说非常不方便且很耗时。为了达到这一点,我不得不等待将近4Gbb的存储空间重做,并花费大约1000万,直到我不知道我的更改工作。
如果它可以继续从失败的地方继续运行,例如从此行开始,那将是很好的
RUN curl -o- -L https://deb.nodesource.com/setup_12.x | bash -
我想知道如何实现这一目标?还是您有更好的方法来解决此问题?
答案 0 :(得分:1)
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的下一个构建开始,然后构建其余的层。
解决方法:
RUN curl -o- -L https://yarnpkg.com/install.sh | bash -