为什么Docker ADD命令不复制此文件? [英] Why does Docker ADD command not copy this file?
问题描述
在下面的文件中,文件 apprequirements.txt
已添加到容器中。我知道是因为 pip install
可以工作。但是,不会复制/添加 myworker.py
文件。 为什么?
In the file below, the file apprequirements.txt
is ADDed to the container. I know because pip install
works. However, the myworker.py
file is not copied/added. Why?
FROM python:2.7
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
ADD ./frontend/apprequirements.txt /code
RUN pip install -r apprequirements.txt
ADD ./backend/myworker.py /code
我使用docker-compose运行它,您可以在 https://github.com/AvidSoftware-be/Docker-compose-test
I run this with docker-compose, you can see the whole example on https://github.com/AvidSoftware-be/Docker-compose-test
推荐答案
深入研究您的存储库后,这就是我的结论:
After a deep review into your repo, this is my conclusion:
您的Dockerfile很好,它应该执行的操作。它会创建一个图像,在该图像内创建一个文件夹 / code
,并复制了两个文件 apprequirements.txt
和 myworker.py
。
Your Dockerfile is fine, it does what is supposed to do. It creates an image, inside that image a folder /code
was created and two files were copied apprequirements.txt
and myworker.py
.
在 docker-compose.yml
文件,您需要具有以下内容:
Inside the docker-compose.yml
file you have this line:
volumes:
- ./frontend:/code
这意味着在运行 docker-compose up
命令后, b $ b泊坞窗将在 / code
现有目录上装载一个volumen。
This means that after you run the docker-compose up
command,
docker is going to mount a volumen over the /code
existing directory.
<$的内容不会从容器中删除c $ c> / code ,但是它会被屏蔽,因为已挂载的目录已挂载在现有文件的顶部。文件仍在容器中,但无法访问。
The content of /code
isn't removed from the container, however it is "masked", because the mounted directory is mounted on top of the existing files. The files are still in the container, but there are not reachable.
注意:文件夹 ./ frontend
包含文件 apprequirements.txt这就是为什么您认为仅添加了一个文件的原因。
Note: the folder ./frontend
includes the file 'apprequirements.txt' is why you believe that only one file was added.
这篇关于为什么Docker ADD命令不复制此文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!