我正在使用Chromium fork docker builder图像。我更喜欢为构建缓存安装一些卷。是否可以在建立图像(docker build -t mychromiumfork_builder .
)?
FROM ubuntu:16.04
# Adjust env
ENV SRC="/mychromiumfork/src" OUT="/mychromiumfork/out" GOOGLE_PLAY_AGREE_LICENSE="1" LC_CTYPE="en_US.UTF-8" CHROME_DEVEL_SANDBOX="1"
# here i'd like to add `ENV CACHE="/mychromiumfork/cache"`
# Install Chromium build dependencies.
RUN echo "deb http://archive.ubuntu.com/ubuntu trusty multiverse" >> /etc/apt/sources.list # && dpkg --add-architecture i386
RUN apt-get update && apt-get install -qy \
git \
build-essential \
clang \
curl \
lsb-core \
sudo \
--no-install-recommends
RUN mkdir -p ${SRC}
# gclient sync prerequisites
COPY .gclient /mychromiumfork
RUN touch /mychromiumfork/.gclient_entries
# Copy sources
COPY src ${SRC}
# required to skip modal dialog with user confirmation (button click required)
RUN echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | sudo debconf-set-selections
RUN chmod +x ${SRC}/build/*.sh
RUN ${SRC}/build/install-build-deps-android.sh --no-prompt \
&& apt-get clean \
&& apt-get autoremove -y
# Install Chromium's depot_tools.
ENV DEPOT_TOOLS /home/developer/depot_tools
RUN git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git $DEPOT_TOOLS
ENV PATH $PATH:$DEPOT_TOOLS
RUN echo -e "\n# Add Chromium's depot_tools to the PATH." >> .bashrc
RUN echo "export PATH=\"\$PATH:$DEPOT_TOOLS\"" >> .bashrc
VOLUME ${OUT}
# here i'd like to add `VOLUME ${CACHE}`
RUN cd /mychromiumfork && gclient sync # here i'd like to add `--cache-dir ${CACHE}`
WORKDIR ${SRC}
#RUN gn gen --args='target_os="android" is_debug=true proprietary_codecs=true ffmpeg_branding="Chrome"' ${OUT}/Debug
#CMD ninja -C ${OUT}/Debug chrome_public_apk
要像这样使用:
docker build -t mychromiumfork_builder . # i'd like to pass -v ${PWD}/cache:/mychromiumfork/cache
docker create -v ${PWD}/out:/mychromiumfork/out --name mychromiumfork mychromiumfork_builder /bin/true
docker run -it --volumes-from=mychromiumfork mychromiumfork_builder
答案 0 :(得分:3)
目前无法使用此功能。目前,卷只能安装在正在运行的容器上而不是图像上。
查看此open issue了解详情。
答案 1 :(得分:0)
如果要缓存频繁重复的操作以使构建更快,那么推荐的方法是将最不频繁更改的命令推送到Docker文件的顶部,并将更频繁更改的文件推送到文件末尾。
你总是可以通过自己构建Dockerfile的顶部来划分和征服,让它标记为'my_cache_build:latest',然后拆分第二个具有
的dockerfileFROM my_cache_build:latest
..
通过这种方式,您可以缓存Docker构建的一部分,以便在重复经常更改的部分时不会花费时间。
https://docs.docker.com/v17.09/engine/userguide/eng-image/dockerfile_best-practices/#run