How to mount a directory in the docker container to the host?

后端 未结 5 2134
广开言路
广开言路 2020-12-31 16:05

It\'s quite easy to mount a host directory in the docker container.

But I need the other way around.

I use a docker container as a development environment fo

5条回答
  •  有刺的猬
    2020-12-31 17:04

    It's possible to do if you use volume instead of filesystem path. It's created for you automatically, if it already doesn't exist.

    docker run -d -v usr_share_wordpress:/usr/share/wordpress --name your_container ... image
    

    After you stop or remove your container, your volume will be stored on your filesystem with files from container.

    You can inspect volume content during lifetime of your_container with busybox image. Something like:

    docker run -it --rm --volumes-from your_container busybox sh
    

    After shutdown of your_container you can still check volume with:

    docker run -it --rm -v usr_share_wordpress:/usr/share/wordpress busybox sh
    

    List volumes with docker volume ls.

提交回复
热议问题