Technical work, should be praised and then see, form a habitCopy the code

Docker use tutorial related series of directories


Volumes are introduced

The data volume provides the following functions: When the container fails, the actual directory of the data volume is stored on the host. Data will not be lost. Starting a new container does not affect data as long as the data volume still exists

Viewing data Volumes

docker volume ls
Copy the code

Creating a Data Volume

docker volume create nginx_vol
Copy the code

View data volume details

docker volume inspect nginx_vol
Copy the code

Create containers with data volumes

docker run -d --name=nginx03 -p 88:80 --mount src=nginx_vol,dst=/usr/share/nginx/html/ nginx
Copy the code

Error: Using –mount

unknown flag: –mount

Solution: Use -v or use version 17.06 or later

docker run -d --name=nginx03 -p 88:80 -v nginx_vol:/usr/share/nginx/html/ nginx
Copy the code

 

Take a look at the directory where the container nginx03 is hosted

ls /var/lib/docker/volumes/nginx_vol/_data
Copy the code

Modify the/var/lib/docker/volumes/nginx_vol / _data while forming the index in the directory. The HTML file

Prove the/var/lib/docker/volumes/nginx_vol / _data while forming files in the directory and nginx03 container is Shared

Docker inspect nginx03Copy the code

Pause the nginx03 container and create the nginx04 container

Found that the data was still not lost

Some students will ask, if these two containers are deleted, will the files of the data volume still exist?

The answer is yes, because the data volume is independent of the container

Note: If the data volume is deleted, the data file does not exist

summary

Volume features:

  1. Data is shared between multiple running containers
  2. When the container is stopped or removed, the data volume still exists
  3. Multiple containers can mount the same volume simultaneously
  4. Data in the volume is deleted only when the volume is deleted
  5. Store the container’s data on a remote host or other storage
  6. /var/lib/docker/volumes/