How to mount volume from container to host in Docker?

Host volumes don’t copy data from the container > host. Host volumes mount over the top of what’s in the container/image, so they effectively replace what’s in the container with what’s on the host.

A standard or “named” volume will copy the existing data from the container image into a new volume. These volumes are created by launching a container with the VOLUME command in it’s Dockerfile or by the docker command

docker run -v myvolume:/var/whatever myimage

By default this is data stored in a “local” volume, “local” being on the Docker host. In your case that is on the VM running Docker rather than your Windows host so might not be easily accessible to you.

You could be mistaking transmission auto generating files in a blank directory for a copy?

If you really need the keep the VM Host > container mappings then you might have to copy the data manually:

docker create --name nginxcopy nginx
docker cp nginxcopy:/etc/nginx C:\path\to\config
docker cp nginxcopy:/var/www/html C:\path\to\html
docker rm nginxcopy

And then you can map the populated host directories into the container and they will have the default data the image came with.

Leave a Comment