loading data volume docker

docker data volume loading notes

Essential to produce some of our services running log, or we need to back up data in the container, and even share data between multiple containers, which necessarily involves data management operations of the container.

Container management data There are two main ways: 1. Data volume 2. Data volume container

1. Data volume

Data volume is a container used for special directory, it bypasses the file system, it can provide a lot of useful features:

  • Data volume can be shared and reused between the vessel
  • The data volume changes will take effect immediately
  • Updates to the data volume will not affect the image
  • Volume will always exist until there are no containers

2. The volume of data to create, view, delete

docker run --name testweb -d -p 92:80 -v testwebvloume:/usr/share/nginx/html/ nginx:v3
#利用nginx:v3镜像创建了一个名为testweb的容器,对外暴露的端口号是92,将/usr/share/nginx/html目录与数据卷testwebvloume 映射。
docker volume create volume_name #表示创建一个数据卷。
docker volume ls #列出数据卷列表
docker volume rm volume_name #删除指定数据卷
docker volume inspect volume_name #查看数据卷的详细信息
例如:docker volume inspect testwebvloume
[
    {
        "CreatedAt": "2019-07-26T11:55:06+08:00",
        "Driver": "local",
        "Labels": null,
        "Mountpoint": "/var/lib/docker/volumes/testwebvloume/_data",#表示数据卷的挂载点也就是挂载位置
        "Name": "testwebvloume",
        "Options": null,
        "Scope": "local"
    }
]
#使用docker volume --help 帮助查看命令使用指南
Usage:  docker volume COMMAND
Manage volumes
Commands:
  create      Create a volume
  inspect     Display detailed information on one or more volumes
  ls          List volumes
  prune       Remove all unused local volumes
  rm          Remove one or more volumes

3. Data volume container

If you need to share some data continually updated between the container, the easiest way is to use the data volume of the container, data volume container is actually an ordinary container, designed to provide data for other container volume to mount.

 docker run -v commmon:/usr/share/nginx/html/ --name commvolume nginx:v3
 #创建一个名为commvolume的容器,他的数据目录挂载到common中
 docker run -d -p 99:80 --name commweb --volumes-from  commvolume  nginx:v3
 #创建一个容器名为commweb,它的数据卷来自于commvolume 容器。

Guess you like

Origin www.cnblogs.com/jasonboren/p/11370380.html