Use the volume of Docker storage volume

Source: Internet
Author: User
Tags docker run

A recent project to use Data Volume, here is a simple record.

Data volumes can be used to store data for Docker applications, or to share data between Docker containers. A data volume is presented to a Docker container in the form of a directory that supports sharing between multiple containers, and the modification does not affect mirroring.

Characteristics:

Data volumes can be shared and reused between containers

Changes to the data volume will take effect immediately

Updates to the data volume do not affect mirroring

The data volume is always present by default, even if the container is deleted

 

1. Create a data volume

Docker Volume Create Vol1

View all data volumes

Docker Volume LS

Use the following command in the host to view the specified data volume information

Docker Volume Inspect Vol1

[
{
"Driver": "Local",
"Labels": {},
"Mountpoint": "/var/lib/docker/volumes/vol1/_data",
"Name": "Vol1",
"Options": {},
"Scope": "Local"
}
]

2. Using data volumes

(1) Use the "-V in-Container directory" method

Docker run-d-P--name web-v/webapp training/webapp python app.py

This way Docker will mount a local _data directory into the WebApp directory in the container, but after the Web container is deleted, the directory of _data on the host and its contents will remain, and the newly launched container is no longer able to use the directory, which means Existing data cannot be reused automatically.

(2) Use-V to mount a directory/file on a host to a container directory/file

Docker run-d-P 23333:80-v vol1:/store training/webapp python app.py or use--mount source=vol1, Target=/store

The data volume that is created is vol1 to the container's/store directory, which can be understood as a directory mapping, which allows all containers to share host data so that all container data can be affected by changing the host's data source. Also, when you restart the container, you can use the same method to hang the Vol1 directory in the new container again, so that you can achieve the purpose of data persistence.

3. Deleting data volumes

Docker Volume RM vol1

Use the volume of Docker storage volume

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.