首页 > 解决方案 > 我可以在构建 Docker 映像时挂载卷吗?

问题描述

我正在研究 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

标签: docker

解决方案


这暂时不可用。目前,卷只能挂载到正在运行的容器上,而不能挂载到镜像上。

检查这个未解决的问题以获取更多信息。


推荐阅读