Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Run: Mounted Volume not showing change in files

I am struggling with running the latest changes. Below are the details.

Dockerfile

FROM python:3.7.3

RUN mkdir -p /usr/apps

COPY test.py /usr/apps

RUN pip install mindsdb
CMD [ "python","test.py" ]

Build

docker build -t py37:custom . 

Run

docker run -it -v /Development/PetProjects/mindsdb:/usr/apps/  py37:custom

But it shows only the changes at the time of build.

like image 959
Volatil3 Avatar asked Oct 28 '25 02:10

Volatil3


1 Answers

First of all while starting your container you are not using volumes but bind mounts. So you mount directory /Development/PetProjects/mindsdb on your host machine to /usr/apps/ directory. Every change made to files on your host machine in this directory, will be visible in the container, and the other way round.

If you wanted to use volumes, you could create one using docker volume create command and then running container with this volume : docker container run -v volume_name:path_in_container image_name. Then you would be able to stop container and run it again by passing this volume to run command and changes to path_in_container directory could be stored across container creations.

Another thing is that you are trying to mount /usr/apps/ in your container and you copied a python script there using Dockerfile. Note that in you current docker run command contents of /Development/PetProjects/mindsdb will replace content of /usr/apps/ in your container and if you do not have your script in /Development/PetProjects/mindsdb - script will not be visible in the container.

Moreover your CMD seems not to work because of path relativeness. You should change your CMD to CMD [ "python","/usr/apps/test.py" ] or use WORKDIR option - WORKDIR /usr/apps/ so your python command could be executed from this directory and script could be visible there.

More information about differences between volumes and bind mounts can be found in docker documentation.

like image 60
Michał Krzywański Avatar answered Oct 30 '25 21:10

Michał Krzywański



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!