Docker Community Forums

Share and learn in the Docker community.

Docker won't copy files into local volume

So, I’m trying to use volumes in Docker.

I have a container where inside a folder called /db stores a .sql file used to create a .db

If I create a volume and attach the volume with sudo docker run -v my_volume:/app/db -it --privileged accumulator everything works smoothly as the content of the /app/db of the container is correctly copied to the volume and used from there.

If, instead, I want to use an host directory, using for istance sudo docker run -v /home/nicola/Documents/db:/app/db -it --privileged accumulator docker correctly links the folders but it doesn’t copy the content on the /db folder inside the container to the /db folder on the host.

Is it a normal behavior?

Yes, this is the expected behavior: content is only copied from the image into an empty volume, not into an empty “bind mount” which is what you’re using now. If you need this for bind mounts, then you’ll need to have your container do that. Docker won’t do it for you.

(For example the WordPress image does that.)

1 Like