Why does Docker ADD command not copy this file?

2019-07-15 08:25发布

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

I run this with docker-compose, you can see the whole example on https://github.com/AvidSoftware-be/Docker-compose-test

1条回答
Lonely孤独者°
2楼-- · 2019-07-15 08:37

After a deep review into your repo, this is my conclusion:

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.

Inside the docker-compose.yml file you have this line:

volumes:
  - ./frontend:/code

This means that after you run the docker-compose up command, docker is going to mount a volumen over the /code existing directory.

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.

Note: the folder ./frontend includes the file 'apprequirements.txt' is why you believe that only one file was added.

查看更多
登录 后发表回答