我的项目层次结构是这样的:
docker-flowcell-restore
docker-flowcell-restore
config
src
requirements.txt
Dockerfile
我想使用Copy将我的src文件添加到我的docker镜像中。到目前为止,我的Docker镜像具有以下内容:
FROM ubuntu
RUN apt-get update && apt-get install -y \
python3 \
python3-pip
ENV INSTALL_PATH /docker-flowcell-restore
RUN mkdir -p $INSTALL_PATH
WORKDIR $INSTALL_PATH
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
ENTRYPOINT ['python', 'docker-flowcell-restore/src/main.py']
如何添加src文件夹内容的副本?谢谢。
答案 0 :(得分:1)
您可以执行以下操作:
FROM ubuntu
RUN apt-get update && apt-get install -y \
python3 \
python3-pip
ENV INSTALL_PATH /docker-flowcell-restore
RUN mkdir -p $INSTALL_PATH
WORKDIR $INSTALL_PATH
COPY requirements.txt requirements.txt
COPY ./src <the path inside the container where you want src>
RUN pip install -r requirements.txt
ENTRYPOINT ['python', 'docker-flowcell-restore/src/main.py']
这假设您正在从Dockerfile所在的目录构建映像。
答案 1 :(得分:1)
在pip install命令后添加副本。这会利用docker layer cache,因此在更改代码的不同部分后,不会重新运行所有需求的安装:
FROM ubuntu
RUN apt-get update \
&& apt-get install -y \
python3 \
python3-pip \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
ENV INSTALL_PATH /docker-flowcell-restore
RUN mkdir -p $INSTALL_PATH
WORKDIR $INSTALL_PATH
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY src/ src/
ENTRYPOINT ['python', 'src/main.py']
我还在执行安装后添加了清理apt缓存的步骤,并在定义WORKDIR
后调整了入口点。