How to mount volume from container to host in Docker?

后端 未结 2 660
走了就别回头了
走了就别回头了 2020-12-08 17:02

I have a question regarding the whole data volume process in Docker. Basically here are two Dockerfiles and their respective run commands:

Dockerfile 1 -

2条回答
  •  清歌不尽
    2020-12-08 17:44

    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.

提交回复
热议问题