Docker Learning Day (Docker data volume management)

1.Docker data volume management

  In Docker in order to achieve persistent data (so-called persistent data Docker i.e. data is not ended with the end of the Container ), the need for data from the host to mount into the container. Docker currently provides three different ways to mount the data from the host to the vessel:

1.volumes: Docker part of the host file system management (default file location: / var / lib / docker / volumes) Common

From the above chart shows us to the / var / lib / docker / volumes under long file name directory Some two others are anonymous at this time we set when creating

2.bind mounts: may be stored anywhere on the host system

However, bind mount at different host systems are not portable, such as Windows and Linux directory structure is not the same, bind mount points to host directory can not be the same. This is also the reason why the bind mount in Dockerfile not appear, because it would not be Dockerfile transplant.
3.tmpfs: Mount stored in memory in the host system, the host does not write to the file system is not used

Schematic diagram of three ways:

Use 2.Volume data volume

Volume Management

EDC-nignx the Create Volume Docker-Vol // create a custom container volume 
Docker Volume LS  // View all container volume 
Docker Volume EDC-the Inspect nginx-Vol // View details information specified container volume

Create a container with a volume

RUN = -d Expediting IT --name Docker EDC Nginx -p- 8800 : 80 -v-EDC-Nginx Vol: / usr / Share / Nginx / HTML Nginx
 // -v loading data representative of the volume, as used herein, since a given data volume edc-nginx-vol, and the data volume mount / usr / share / nginx / html ( yum this directory is installed nginx default directory page).
// If not specified by -v, then the default Docker will help us create anonymous data mapping and mount volumes.

Clean up Volumes:

Container EDC-STOP Nginx Docker // suspended container 
Docker Container RM EDC-Nginx // out of the container 
Docker Volume RM EDC-nignx-Vol // delete the custom data volume

3.Bind Mounts of use

Bind Mounts bind mounts

RUN -it --name = -d Docker nginx-the Test -v / app / wwwroot: / usr / report this content share / nginx / HTML nginx
 // This specifies the / app / wwwroot directory on the host (if not created automatically ) mounted to / usr / share / nginx / html ( this directory is the default yum install nginx web directory).

Verify binding

docker inspect nginx-test

Clear up

docker container stop nginx-test
docker container rm nginx-test

 

Reference to learn: https: //www.cnblogs.com/edisonchou/p/docker_volumes_introduction.html (recommended)

Guess you like

Origin www.cnblogs.com/xhds/p/12319745.html