Brief Docker Data Persistence

Docker data persistence in two ways:
data volume (Data Volumes)
mounted Host Directory (Bind mounts)

Data volume:
data volumes can be shared and reused between containers
on the data volume changes will take effect immediately
update the data volume will not affect the image
data volume default will always exist, even if the container is deleted
$ docker volume create my-vol # create a data volume
$ docker volume ls # to see what volume
$ docker volume inspect my-vol # vol View details
$ docker run -d -P --name web -v my-vol: / wepapp training / webapp python app.py # loading the data volume of the container / webapp directory
when using -P flag, Docker randomly mapped to a port of 49,000 - 49,900 vessel open interior network ports.
$ Docker inspect web # View container details
$ docker rm -f web # force the removal of a running container
$ docker volume rm my-vol # Delete Volume
$ docker volume prune # clean up useless volume

Mount Host Directory:
$ Docker RUN -d -P --name Web -v / src / webapp: / opt / the webapp Training / Python app.py the webapp # to host the / src / webapp directory is mounted to the container / opt / webapp directory
$ docker run -d -P --name web -v $ HOME / .bash_history: /root/.bash_history training / webapp python app.py # to the host file $ HOME / .bash_histor mounted to the container

Guess you like

Origin blog.51cto.com/dongdong/2424900