在编写 Dockerfile 时,我们可能需要将多条指令合并成一行,这样语法简洁,并且可以减少镜像层数。 将多条 COPY 指令合并为一条 比如,我们的 Dockerfile 里面有这样的语句: 1FROM python:2.7-stretch 2WORKDIR /xdhuxc/ 3COPY dingtalk_callback.py /xdhuxc/ 4COPY requirements.txt /xdhuxc/ 5COPY settings.py /xdhuxc/ 6RUN pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple 7ENTRYPOINT ["python", "-u", "/xdhuxc/dingtalk_callback.py"] 我们想把多个 COPY 指令合并成一条,可以改写该 Dockerfile 为如下形式: 1FROM python:2.7-stretch 2WORKDIR /xdhuxc/ 3COPY dingtalk_callback.py requirements.txt settings.py /xdhuxc/ 4RUN pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple 5ENTRYPOINT ["python", "-u", "/xdhuxc/dingtalk_callback.py"] 或……
Continue reading