docker swarm 数据卷操作


docker swarm 数据卷操作

 

 

**********************

docker volume

 

命令格式:docker volume command

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

Run 'docker volume COMMAND --help' for more information on a command.

create:创建数据卷

inspect:查看数据卷详细信息

ls:列出数据卷

prune:删除不使用的数据卷

rm:删除数据卷

 

 

******************

docker vloume create

 

命令格式:docker volume create [options] volume_name

Usage:	docker volume create [OPTIONS] [VOLUME]

Create a volume

Options:
  -d, --driver string   Specify volume driver name (default "local")
      --label list      Set metadata for a volume
  -o, --opt map         Set driver specific options (default map[])

 

 

**********************

示例

 

创建数据卷:docker volume create my_volume

[root@centos docker]# docker volume create my_volume
my_volume

 

查看数据卷信息

[root@centos docker]# docker volume inspect my_volume
[
    {
        "CreatedAt": "2020-08-23T10:29:12+08:00",
        "Driver": "local",
        "Labels": {},
        "Mountpoint": "/var/lib/docker/volumes/my_volume/_data",
        "Name": "my_volume",
        "Options": {},
        "Scope": "local"
    }
]

宿主机目录:/var/lib/docker/volumes/my_volume/_data

 

 

创建服务时,添加数据卷

[root@centos docker]# docker service create --mount type=volume,source=my_volume,target=/test --name redis redis
7x5mthpymieqrswmsj06dklsx
overall progress: 1 out of 1 tasks 
1/1: running   [==================================================>] 
verify: Service converged 

 

服务创建后,添加数据卷

[root@centos docker]# docker service update --mount-add type=volume,source=add_volume,target=/test2 redis
redis
overall progress: 1 out of 1 tasks 
1/1: running   [==================================================>] 
verify: Service converged 

 

服务创建后,删除数据卷

[root@centos docker]# docker service update --mount-rm /test2 redis
redis
overall progress: 1 out of 1 tasks 
1/1: running   [==================================================>] 
verify: Service converged 

 

 

**********************

示例 2

 

创建服务时,添加数据卷

[root@centos docker]# docker service create --mount type=bind,source=/usr/docker/test,target=/test --name redis redis
6u8rwge2zlsmin8gjsgcdp5c9
overall progress: 1 out of 1 tasks 
1/1: running   [==================================================>] 
verify: Service converged 

数据卷添加、删除同上操作

 

 

你可能感兴趣的:(docker)