I am using #docker run -it -v /tmp:/tmp/a ubuntu:latest to create a docker container. After my docker host restarts, my container dies (Ofcourse).
When I attempt to start my container again with #docker start <container_name>, the volume mapping is lost.
Is there any manner in which I can ensure that whenever I restart a docker container, the volume mapping can still persist with my local docker host files ?
Guess /tmp (even though having the same mount point) has not the same identity between boot cycles. I guess it is similar to when you map a host folder into the container and then mount something into that host folder - the container will still see the old content the host folder had before the mount, as the container will still only know about the inode before the mount, but not the changed inode after mount. The bind source is simply not exact the same bind source as it was at the point in time the container was created. Try a different folder or use docker named volumes.
Thank you @meyay , for your response.
I am using MacOS - docker desktop to run docker, so may be I can my host OS is MacOS.
What I am looking for is to make changes to some files in docker container and save them to persistent store in my Mac. I also want changes to my files directly from my mac, and want them to be reflected in docker container across reboots. Would you kindly suggest if docker volume can replicate or point to a specific folder in Mac ?
As I am not using a mac, I can only assume that it should work. @rimelek can tell you for sure
It works on macOS Monterey (Macbook Air 4, m1), Docker Desktop 4.12. Can you share the commands that gave you the idea that the volume mapping was lost?
Just to be sure, do you know that this command starts the container without entering the container? You can start the container in the foreground this way:
docker start -a <container_name>
HI @rimelek @meyay
Thank you so much ! I wasn’t sure if the mounts are persistent and were designed to work across stop/start of container. I just tried with a new container and it worked for me. I then investigated on why it did not work for my original container.
I found that it did not work previously for me because the local mount directory was a ‘Google Drive for Desktop’ share. The files keeps changing & syncing from google drive. I suppose after I signed out and signed in again, docker couldn’t identify the directory volume, although it was at the same location.
Would you know what is the reason, or if I can put the mapping/inode descriptors somewhere in the container settings ?
This is what happens automatically. If you lose the mount, then the inode changed. You can try to mount a parent folder.
Thank you @rimelek.
Parent would be my home directory which would be extensive. I’ll try to create a directory link maybe and see if that works. Alternatively, I will try to explore either docker volumes or edit the docker configuration somehow.