docker存储配置与管理
查看docker info
[root@hmm overlay2]# docker info
Client: Docker Engine - Community
Version: 25.0.3
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc.)
Version: v0.12.1
Path: /usr/libexec/docker/cli-plugins/docker-buildx
compose: Docker Compose (Docker Inc.)
Version: v2.24.6
Path: /usr/libexec/docker/cli-plugins/docker-compose
Server:
Containers: 1
Running: 0
Paused: 0
Stopped: 1
Images: 5
Server Version: 25.0.3
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Using metacopy: false
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 runc
Default Runtime: runc
Init Binary: docker-init
containerd version: ae07eda36dd25f8a1b98dfbf587313b99c0190bb
runc version: v1.1.12-0-g51d5e94
init version: de40ad0
Security Options:
seccomp
Profile: builtin
Kernel Version: 3.10.0-862.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 1.936GiB
Name: hmm
ID: ef4c910e-c299-4bde-b4b8-e6bd39ec99ee
Docker Root Dir: /var/lib/docker
Debug Mode: false
Experimental: false
Insecure Registries:
127.0.0.0/8
Registry Mirrors:
http://registry.docker-cn.com/
Live Restore Enabled: false
WARNING: API is accessible on http://0.0.0.0:2375 without encryption.
Access to the remote API is equivalent to root access on the host. Refer
to the 'Docker daemon attack surface' section in the documentation for
more information: https://docs.docker.com/go/attack-surface/
[root@hmm overlay2]#
查看驱动的本地存储
[root@hmm ~]# ls /var/lib/docker/
buildkit containers engine-id image network overlay2 plugins runtimes swarm tmp volumes
[root@hmm ~]# cd /var/lib/docker/
[root@hmm docker]# cd overlay2/
[root@hmm overlay2]# ls
26625907d00815747e8cac482a1a62ff06e153543cf914c4edf95d0846b15ec5
3d8c300ff053bd2ca4e62612c8209dd2e8358845228b4a76aab105358afa37ab
51056850a6566edcd8c8e3a0cd507cb4ca421463e18203782c4aa8515dabc146
51056850a6566edcd8c8e3a0cd507cb4ca421463e18203782c4aa8515dabc146-init
5ef601e966da6df616f65b262570adbb5733017d770d94c5bc8c7e6b188ad881
7987fae3b1b5590b9c0d4d8e38011c6715df2026231afe3c37382200b9b1a1ff
97l4r6nxwu2mpz0n0cxlr973v
backingFsBlockDev
db0600235154dccf95a6a3ad038fe630024448364895e81409ccb072c07269e2
e41egh7ju6i7x0o7qrvk4gy4k
f7c270ad6461a794e6e169c944fdd2cb6d13456859100d83d9a6937c1ee5dbb7
hyqu74kjsemkx24bv71cfyhqk
l
lgnbtonjnna4nt95y2ume8l5i
[root@hmm overlay2]#
修改damon.json文件,更改存储驱动
[root@hmm overlay2]# cat /etc/docker/daemon.json
{
"registry-mirrors":["http://registry.docker-cn.com"],
"storage-driver": "vfs"
}
[root@hmm overlay2]# docker info |grep storage
WARNING: API is accessible on http://0.0.0.0:2375 without encryption.
Access to the remote API is equivalent to root access on the host. Refer
to the 'Docker daemon attack surface' section in the documentation for
more information: https://docs.docker.com/go/attack-surface/
[root@hmm overlay2]# docker info |grep vfs
WARNING: API is accessible on http://0.0.0.0:2375 without encryption.
Access to the remote API is equivalent to root access on the host. Refer
to the 'Docker daemon attack surface' section in the documentation for
more information: https://docs.docker.com/go/attack-surface/
Storage Driver: vfs //更改成功
[root@hmm overlay2]#
docker存储驱动
卷
[root@hmm ~]# 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 unused local volumes
rm Remove one or more volumes
Run 'docker volume COMMAND --help' for more information on a command.
[root@hmm ~]# docker volume create --help
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[]) //指定卷的大小,使用什么方式进行挂载,驱动等
- 创建一个普通卷
root@hmm ~]# docker volume ls
DRIVER VOLUME NAME
[root@hmm ~]# docker volume create test-vol1
test-vol1
[root@hmm ~]# docker volume inspect test-vol1
[
{
"CreatedAt": "2024-04-24T00:42:49+08:00",
"Driver": "local",
"Labels": null,
"Mountpoint": "/var/lib/docker/volumes/test-vol1/_data",
"Name": "test-vol1",
"Options": null,
"Scope": "local"
}
]
[root@hmm ~]#
[root@hmm ~]# cd /var/lib/docker/volumes/
[root@hmm volumes]# ls
backingFsBlockDev metadata.db test-vol1
[root@hmm volumes]# cd test-vol1/
[root@hmm test-vol1]# ls
_data
[root@hmm test-vol1]# cd _data/
[root@hmm _data]# ls
[root@hmm _data]# touch yun3_test
[root@hmm _data]# ls
yun3_test
- 创建一tmpfs卷
[root@hmm _data]# docker volume create --driver local --opt type=tmpfs --opt device=,uid=1000 teste-vol2
teste-vol2
[root@hmm _data]# docker volume inspect teste-vol2
[
{
"CreatedAt": "2024-04-24T01:00:21+08:00",
"Driver": "local",
"Labels": null,
"Mountpoint": "/var/lib/docker/volumes/teste-vol2/_data",
"Name": "teste-vol2",
"Options": {
"device": "tmpfs",
"o": "size=100m,uid=1000",
"type": "tmpfs"
},
"Scope": "local"
}
]
- 创建带元数据的卷
[root@hmm _data]# docker volume create --label class=yun3 \
> --label age=20 \
> test-vol3
test-vol3
[root@hmm _data]# docker volume inspect test-vol3
[
{
"CreatedAt": "2024-04-24T01:01:49+08:00",
"Driver": "local",
"Labels": {
"age": "20",
"class": "yun3"
},
"Mountpoint": "/var/lib/docker/volumes/test-vol3/_data",
"Name": "test-vol3",
"Options": null,
"Scope": "local"
}
]
查看卷
- 普通查看
[root@hmm _data]# docker volume ls
DRIVER VOLUME NAME
local 421a92d5fae8a818a2dfdae251f86d23d62b0a02d26134836d7140bbb63a7e76
local 73401cb13134c689095a345c85ad635862c5e16eac4ea3c1c9402f6a85b38bf6
local test-vol1
local test-vol3
local teste-vol2
- 简单筛选
[root@hmm _data]# docker volume ls -f label=age //筛选标签含age的卷
DRIVER VOLUME NAME
local test-vol3
[root@hmm _data]# docker volume ls -f name=vol
DRIVER VOLUME NAME
local test-vol1
local test-vol3
local teste-vol2
[root@hmm _data]# docker volume ls -f name=vo3
DRIVER VOLUME NAME
[root@hmm _data]# docker volume ls -f name=3
DRIVER VOLUME NAME
local 421a92d5fae8a818a2dfdae251f86d23d62b0a02d26134836d7140bbb63a7e76
local 73401cb13134c689095a345c85ad635862c5e16eac4ea3c1c9402f6a85b38bf6
local test-vol3
- 只显示名字
[root@hmm _data]# docker volume ls -q
421a92d5fae8a818a2dfdae251f86d23d62b0a02d26134836d7140bbb63a7e76
73401cb13134c689095a345c85ad635862c5e16eac4ea3c1c9402f6a85b38bf6
test-vol1
test-vol3
teste-vol2
[root@hmm _data]#
- 普通格式化输出
[root@hmm _data]# docker volume ls --format "{{.Name}}***{{.Scope}}***{{.Mountpoint}}"
421a92d5fae8a818a2dfdae251f86d23d62b0a02d26134836d7140bbb63a7e76***local***/var/lib/docker/volumes/421a92d5fae8a818a2dfdae251f86d23d62b0a02d26134836d7140bbb63a7e76/_data
73401cb13134c689095a345c85ad635862c5e16eac4ea3c1c9402f6a85b38bf6***local***/var/lib/docker/volumes/73401cb13134c689095a345c85ad635862c5e16eac4ea3c1c9402f6a85b38bf6/_data
test-vol1***local***/var/lib/docker/volumes/test-vol1/_data
test-vol3***local***/var/lib/docker/volumes/test-vol3/_data
teste-vol2***local***/var/lib/docker/volumes/teste-vol2/_data
[root@hmm _data]#
- json格式 格式化输出
[root@hmm _data]# docker volume ls --format "{{json .Name}}***{{json .Scope}}***{{json .Mountpoint}}"
"421a92d5fae8a818a2dfdae251f86d23d62b0a02d26134836d7140bbb63a7e76"***"local"***"/var/lib/docker/volumes/421a92d5fae8a818a2dfdae251f86d23d62b0a02d26134836d7140bbb63a7e76/_data"
"73401cb13134c689095a345c85ad635862c5e16eac4ea3c1c9402f6a85b38bf6"***"local"***"/var/lib/docker/volumes/73401cb13134c689095a345c85ad635862c5e16eac4ea3c1c9402f6a85b38bf6/_data"
"test-vol1"***"local"***"/var/lib/docker/volumes/test-vol1/_data"
"test-vol3"***"local"***"/var/lib/docker/volumes/test-vol3/_data"
"teste-vol2"***"local"***"/var/lib/docker/volumes/teste-vol2/_data"
[root@hmm _data]#