Why does Docker ADD command not copy this file?

孤者浪人 提交于 2019-12-11 00:20:33

问题


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:


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.



来源:https://stackoverflow.com/questions/35466045/why-does-docker-add-command-not-copy-this-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!