docker data volume vs mounted host directory

后端 未结 4 1840
悲&欢浪女
悲&欢浪女 2020-11-30 22:31

We can have a data volume in docker:

$ docker run -v /path/to/data/in/container --name test_container debian
$ docker inspect test_container
...
Mounts\": [
         


        
4条回答
  •  一个人的身影
    2020-11-30 23:12

    The difference between host directory and a data volume is in that that Docker manages the latter by placing it into the $DOCKER-DATA-DIR/volumes directory and attaching a reference to it (names or randomly generated ids). That is you get a little bit of convenience.

    Both host directories and data volumes are directories on the host. Both are host dependent. You can't reference either of them in a Dockerfile; the VOLUME directive creates a new nameless (with randomly generated id) volume every time you launch a new container and cannot reference an existing volume.

    * $DOCKER-DATA-DIR is /var/lib/docker here unless you changed the defaults.

提交回复
热议问题