Docker Community Forums

Share and learn in the Docker community.

Mounting a data volume without overwriting the container directory

(Saltzmanjoelh) #1

How do I mount an existing container directory to the host without deleting the files in the container’s directory?

docker run -it -v ~/myHostDirectory:~/someContainerDirectory imageName /bin/bash

~/someContainerDirectory in the container gets cleared out

(Jeff Anderson) #2


It isn’t that it is deleting files inside the container, but they are hidden. This is simply how mounts work. If I were to plug in a flash drive and mount it to ~/someDirectory, then anything in ~/someDirectory would be masked by the files available in the new mount. The volumes feature in docker works the same way.


(Rishu1102) #3

@programmerq Is there any workaround for this? I am very new to Docker and volumes.