docker——存储配置与管理
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]#
整合(tmpfs类型的卷并查看)
[root@hmm ~]# docker volume create --driver local --opt type=tmpfs --opt device=tmpfs --opt o=size=100m,uid=1000 --label school=hbkj --label type=tmpfs yum3-vol
yum3-vol
[root@hmm ~]# docker volume inspect yum3-vol
[
{
"CreatedAt": "2024-04-24T01:24:35+08:00",
"Driver": "local",
"Labels": {
"school": "hbkj",
"type": "tmpfs"
},
"Mountpoint": "/var/lib/docker/volumes/yum3-vol/_data",
"Name": "yum3-vol",
"Options": {
"device": "tmpfs",
"o": "size=100m,uid=1000",
"type": "tmpfs"
},
"Scope": "local"
}
]
[root@hmm ~]# docker volume inspect yum3-vol --format "{{.Labels}}"
map[school:hbkj type:tmpfs]
[root@hmm ~]# docker volume inspect yum3-vol --format "{{.Options.o}}"
size=100m,uid=1000
卷的删除
- 普通删除
[root@hmm ~]# docker volume rm
- 批量删除
[root@hmm ~]# docker volume rm $(docker volume ls -q)
421a92d5fae8a818a2dfdae251f86d23d62b0a02d26134836d7140bbb63a7e76
73401cb13134c689095a345c85ad635862c5e16eac4ea3c1c9402f6a85b38bf6
test-vol1
test-vol3
teste-vol2
yum3-vol
[root@hmm ~]#
- 删除没有被使用的卷
[root@hmm ~]# docker volume ls
DRIVER VOLUME NAME
local 1e178a48a255713f49ade0accaf6c9b1bef0d066533aaec8a90e67eb5a9365b9
local 6aace89bcae20a35d71b915fce665af35d8507080f557290c0a5154af361f6c2
local c84db42866fff653c3f98d8d0cbde8edce0a58bef2dc9206966ad6a3a4d4ec3f
local f46a96daf31613f649951726b12447484faedb6c76ee331baba3b98597429125
local fb8d3a9e08451fb44e6d8474a8e780a1418ef15bf3921903c63b12384730c9cb
local yum3-vol1
local yum3-vol2
local yum3-vol3
[root@hmm ~]# docker volume prune
WARNING! This will remove anonymous local volumes not used by at least one container. //是否要删除未命名的卷(没有被容器使用的)
Are you sure you want to continue? [y/N] y
Deleted Volumes:
c84db42866fff653c3f98d8d0cbde8edce0a58bef2dc9206966ad6a3a4d4ec3f
6aace89bcae20a35d71b915fce665af35d8507080f557290c0a5154af361f6c2
fb8d3a9e08451fb44e6d8474a8e780a1418ef15bf3921903c63b12384730c9cb
1e178a48a255713f49ade0accaf6c9b1bef0d066533aaec8a90e67eb5a9365b9
f46a96daf31613f649951726b12447484faedb6c76ee331baba3b98597429125
Total reclaimed space: 0B
[root@hmm ~]# docker volume ls
DRIVER VOLUME NAME
local yum3-vol1
local yum3-vol2
local yum3-vol3
[root@hmm ~]#
- 删除有city label的卷
[root@hmm ~]# docker volume create --label city=wuhan
893fe29eef0b484b74f6daab40a655da58b292efc3b2917e539d9ab9b06ac22c
[root@hmm ~]# docker volume create --label city=wuhan
5411c3b489b3f248f245a769068c28aa5b7d2518072867573b65a5cb18909171
[root@hmm ~]# docker volume create --label city=wuhan
2053dc378e4736716c6c86f9dabefeca8189c2895aebaf370f174af309f98a22
[root@hmm ~]# docker volume create --label school=hbkj
ffcdce53e993f14dec484c9387f49f072977ad1ce7ba85d9635eae43582fe83f
[root@hmm ~]# docker volume prune --filter label=city
WARNING! This will remove anonymous local volumes not used by at least one container.
Are you sure you want to continue? [y/N] y
Deleted Volumes:
893fe29eef0b484b74f6daab40a655da58b292efc3b2917e539d9ab9b06ac22c
5411c3b489b3f248f245a769068c28aa5b7d2518072867573b65a5cb18909171
2053dc378e4736716c6c86f9dabefeca8189c2895aebaf370f174af309f98a22
Total reclaimed space: 0B
[root@hmm ~]# docker volume ls
DRIVER VOLUME NAME
local ffcdce53e993f14dec484c9387f49f072977ad1ce7ba85d9635eae43582fe83f
local yum3-vol1
local yum3-vol2
local yum3-vol3
[root@hmm ~]#
绑定挂载(容器文件系统的挂载)
使用docker run 和docker create 命令
- 对于早期docker来说:
1.卷和绑定挂载都可以通过-v,和--mount选项挂载到容器
2.-v一般用于独立容器,--mount一般用于集群服务
3.tmpfs挂载可以使用 --tmpfs选项 - docker 17.06或更高版本:
1.建议使用--mount选项,因为它的语法清晰,定制详细
2.--mount选项也用于独立容器
对比
- -v是将选项组合在一个字段,--mount是将它们分开
- --mount采用键值对写法,支持更多的选项
- -v写法简洁
-v选项
可选选项:
- rw 读写模式
- ro 只读模式
- nocopy 禁止自动复制到卷存储
实例:
1.卷挂载给容器
[root@hqs-docker ~]# docker volume create test-vol
test-vol
[root@hqs-docker ~]# docker volume ls
DRIVER VOLUME NAME
local test-vol
[root@hqs-docker ~]# docker run -ti -v test-vol:/world ubuntu /bin/bash
root@1cba22eb5a0e:/# ls
bin dev home lib32 libx32 mnt proc run srv tmp var
boot etc lib lib64 media opt root sbin sys usr world
2.挂载一个只读的卷
[root@hmm ~]# docker volume ls
DRIVER VOLUME NAME
local test-vol
[root@hmm ~]# docker run -tid --name test-or -v test-vol:/world:ro centos
d0ef668fa014863c7b5f224593e3bd3856af24aaf2bc51e7bef58bab919f8686
[root@hmm ~]# docker exec -ti test-or /bin/bash
[root@d0ef668fa014 /]# cd /world/
[root@d0ef668fa014 world]# ls
aaa.txt
[root@d0ef668fa014 world]# touvh lll.txt
bash: touvh: command not found // 报错!!!因为这个是一个只读的卷
[root@d0ef668fa014 world]#
--mount选项
特殊的键:
- type
- souce(src)
- destination(sat,target)
- readonly
案例:
- 普通案例:
[root@hmm ~]# docker run -tid --name test01 --mount source=test-vol,target=/app \
> centos
8b1c4a5677552cb54227eb21da671ee6952f0d54d2f8978a85404db10ed893a9
[root@hmm ~]# docker volume inspect test-vol
[
{
"CreatedAt": "2024-04-24T02:42:13+08:00",
"Driver": "local",
"Labels": null,
"Mountpoint": "/var/lib/docker/volumes/test-vol/_data",
"Name": "test-vol",
"Options": null,
"Scope": "local"
}
]
[root@hmm ~]# docker exec -ti test01 /bin/bash
[root@8b1c4a567755 /]# cd app/
[root@8b1c4a567755 app]# touch yun3
[root@8b1c4a567755 app]# ls
aaa.txt yun3
[root@8b1c4a567755 app]#
2.创建只读卷
[root@hmm ~]# docker run -tid --name test02 --mount source=test-vol2,target=/app,readonly centos
5f713ee2925b0ef30843c634c5587cec1d804cf2386372ff1a0f79c5b1f44359
[root@hmm ~]# docker exec -ti test02 /bin/bash
[root@5f713ee2925b /]# cd app/
[root@5f713ee2925b app]# touch aaaa
touch: cannot touch 'aaaa': Read-only file system
[root@5f713ee2925b app]#
# --mount 的时候只读使用ro
# -v 的时候只读使用--readonly
- 当你的卷没有创建的时候,你直接run开一个容器,那么它会自动生成卷。
******
-- mount
-v
各写一个
绑定挂载(本地文件)
实例:
- 绑定主机上的目录
- --mount
[root@hmm-docker ~]# mkdir -p source/target
[root@hmm-docker ~]# ls
anaconda-ks.cfg docker-hello source yun1-centos yun3-centos
[root@hmm-docker ~]# cd source/
[root@hmm-docker source]# ls
target
[root@hmm-docker source]# docker run -tid --name devtest --mount type=bind,source="$(pwd)"/target,target=/app nginx
3d6aabb4d417de6d2e4e06026b8c7159d7a0c037958a74ec3d3100927377f89c
[root@hmm-docker source]# docker inspect devtest --format "{{json .Mounts}}"
[{"Type":"bind","Source":"/root/source/target","Destination":"/app","Mode":"","RW":true,"Propagation":"rprivate"}]
[root@hmm-docker source]# touch target/yun3.txt
[root@hmm-docker source]# docker exec -ti devtest /bin/bash
root@3d6aabb4d417:/# cd /app/
root@3d6aabb4d417:/app# ls
yun3.txt
root@3d6aabb4d417:/app# exit
exit
- -v
[root@hmm-docker source]# docker run -tid --name devtest2 -v "$(pwd)"/target:/app nginx
1f7769b4dd4ee35779156ef841efb46c2e61b1d091983d4f1c7023c6463ecd8f
[root@hmm-docker source]# docker exec -ti devtest02 /bin/bash
Error response from daemon: No such container: devtest02
[root@hmm-docker source]# docker exec -ti devtest2 /bin/bash
root@1f7769b4dd4e:/# cd /app/
root@1f7769b4dd4e:/app# ls
yun3.txt
root@1f7769b4dd4e:/app# exit
exit
[root@hmm-docker source]# docker inspect devtest2 --format "{{json .mounts}}"
template parsing error: template: :1:7: executing "" at <.mounts>: map has no entry for key "mounts"
[root@hmm-docker source]# docker inspect devtest2 --format "{{json .Mounts}}"
[{"Type":"bind","Source":"/root/source/target","Destination":"/app","Mode":"","RW":true,"Propagation":"rprivate"}]
- 对比,两种创建方法的效果是一样的
[root@hmm-docker source]# docker inspect devtest --format "{{json .Mounts}}"
[{"Type":"bind","Source":"/root/source/target","Destination":"/app","Mode":"","RW":true,"Propagation":"rprivate"}]
[root@hmm-docker source]# docker inspect devtest2 --format "{{json .Mounts}}"
[{"Type":"bind","Source":"/root/source/target","Destination":"/app","Mode":"","RW":true,"Propagation":"rprivate"}]
# 对比,两种方法是一样的
3,绑定挂载时区
[root@hmm-docker source]# date +%z
+0800 //
[root@hmm-docker source]# docker run --rm -ti --name test ubuntu /bin/bash
root@fb955317ef53:/# date +%z
+0000
root@fb955317ef53:/# exit
exit
[root@hmm-docker source]# docker run --rm -ti --name test --mount type=bind,source=/etc/localtime,target=/etc/localtime ubuntu /bin/bash
root@ec7e5c3ce736:/# date +%z
+0800
root@ec7e5c3ce736:/#
该操作可用来绑定配置文件
4. 绑定挂载当前主机上不存在的文件
- -v
[root@hmm-docker /]# cd /
[root@hmm-docker /]# ls
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
[root@hmm-docker /]# docker run -ti --rm -v /doesnt/exist.txt:/foo ubuntu
root@a3c4d1ef5c82:/# ls
bin dev foo lib lib64 media opt root sbin sys usr
boot etc home lib32 libx32 mnt proc run srv tmp var
root@a3c4d1ef5c82:/# cd foo/
root@a3c4d1ef5c82:/foo# ls
root@a3c4d1ef5c82:/foo# touch aaa
root@a3c4d1ef5c82:/foo# ls
aaa
root@a3c4d1ef5c82:/foo# cd ..
root@a3c4d1ef5c82:/# exit
exit
[root@hmm-docker /]# cd doesnt/
[root@hmm-docker doesnt]# ls
exist.txt
[root@hmm-docker doesnt]# cd exist.txt/
[root@hmm-docker exist.txt]# ls
aaa
[root@hmm-docker exist.txt]#
- --mount
[root@hmm-docker exist.txt]# docker run -ti --rm --mount type=bind,source=/doesnt/exist3,target=/foo/ ubuntu
docker: Error response from daemon: invalid mount config for type "bind": bind source path does not exist: /doesnt/exist3.
See 'docker run --help'.
# --mount 不能够进行不存在的目录或文件的挂载
- 对比
-v 会自动创建出来,--mount 直接报错 - 注意: -v自动创建非存在的挂载点的时候,只能自动创建目录(创建不了文件)
- 绑定挂载到容器中的非空目录
- v
[root@hmm-docker /]# docker run -ti --rm --name broken-test -v /root:/etc/yum.repos.d centos
[root@f45442267e77 /]# cd /etc/yum.repos.d/
[root@f45442267e77 yum.repos.d]# ls
--mount centos source yun3-centos
anaconda-ks.cfg docker-hello yun1-centos
[root@f45442267e77 yum.repos.d]#
- -- mount
[root@hmm-docker /]# docker run -ti --rm --name broken-test --mount type=bind,source=/root,target=/etc/yum.repos.d centos
[root@e78a0817f468 /]# cd /etc/yum.repos.d/
[root@e78a0817f468 yum.repos.d]# ls
--mount centos source yun3-centos
anaconda-ks.cfg docker-hello yun1-centos
[root@e78a0817f468 yum.repos.d]#
- 卷容器,一种特殊的容器,专门用来将卷(或绑定挂载)提供给其他容器挂载。
[root@hmm-docker /]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@hmm-docker /]# docker volume ls
DRIVER VOLUME NAME
[root@hmm-docker /]#
[root@hmm-docker /]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@hmm-docker /]# docker volume ls
DRIVER VOLUME NAME
[root@hmm-docker /]# cd /root/
[root@hmm-docker ~]# ls
anaconda-ks.cfg docker-hello source yun3-centos
centos --mount yun1-centos
[root@hmm-docker ~]# docker create -v /dbdata --name dbstore busybox /bin/sh
c8ed1671f0a24ed4f57523790e5ebacc21de7ad082fd6fa77d95e4324d7a54ac
[root@hmm-docker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c8ed1671f0a2 busybox "/bin/sh" 10 seconds ago Created dbstore
[root@hmm-docker ~]# docker volume ls
DRIVER VOLUME NAME
local 771c50903169f3bb73d5cfe6c7403175336d166250bdeb2f161bbbbf557edc1f
[root@hmm-docker ~]# docker inspect dbstore --format "{{json .Mounts}}"
[{"Type":"volume","Name":"771c50903169f3bb73d5cfe6c7403175336d166250bdeb2f161bbbbf557edc1f","Source":"/var/lib/docker/volumes/771c50903169f3bb73d5cfe6c7403175336d166250bdeb2f161bbbbf557edc1f/_data","Destination":"/dbdata","Driver":"local","Mode":"","RW":true,"Propagation":""}]
[root@hmm-docker ~]# docker run --volumes-form dbstore -v $(pwd):/backup ubunutu ^C
[root@hmm-docker ~]# cd /var/lib/docker/volumes/771c50903169f3bb73d5cfe6c7403175336d166250bdeb2f161bbbbf557edc1f/_data
[root@hmm-docker _data]# touch yun3.txt
[root@hmm-docker _data]# touch aaa.txt
[root@hmm-docker _data]# ls
aaa.txt yun3.txt
[root@hmm-docker _data]# cd
[root@hmm-docker ~]# pwd
/root
[root@hmm-docker ~]# docker run --volumes-from dbstore -v $(pwd):/backup ubuntu tar cvfP /backup/backup.tar /dbdata
/dbdata/
/dbdata/yun3.txt
/dbdata/aaa.txt
[root@hmm-docker ~]# ls
anaconda-ks.cfg centos --mount yun1-centos
backup.tar docker-hello source yun3-centos
[root@hmm-docker ~]# du -sh back*
12K backup.tar
[root@hmm-docker ~]#
[root@hmm-docker ~]# docker run -v /dbdata --name dbstroe2 ubuntu
[root@hmm-docker ~]# docker volume ls
DRIVER VOLUME NAME
local 771c50903169f3bb73d5cfe6c7403175336d166250bdeb2f161bbbbf557edc1f
local e4c9d1edede9cb39d9f81385e27dd4b167450d358e32b3928aee3b71a1a5b011
[root@hmm-docker ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1704df7c7fa9 ubuntu "/bin/bash" 18 seconds ago Exited (0) 18 seconds ago dbstroe2
87eb83d613f0 ubuntu "tar cvfP /backup/ba…" About a minute ago Exited (0) About a minute ago dazzling_kirch
c8ed1671f0a2 busybox "/bin/sh" 5 minutes ago Created dbstore
[root@hmm-docker ~]# docker run --volumes-form dbstore2 -v $(pwd):/backup ubuntu bash -c "cd /dbdata && tar xvf backup.tar --strip 1"
unknown flag: --volumes-form
See 'docker run --help'.
[root@hmm-docker ~]# docker run --volumes-form dbstore2 -v $(pwd):/backup ubuntu bash -c "cd /dbdata && tar xvf /backup/backup.tar --strip 1"
unknown flag: --volumes-form
See 'docker run --help'.
[root@hmm-docker ~]# docker run --volumes-from dbstore2 -v $(pwd):/backup ubuntu bash -c "cd /dbdata && tar xvf /backup/backup.tar --strip 1"
docker: Error response from daemon: No such container: dbstore2.
See 'docker run --help'.
[root@hmm-docker ~]# docker run --volumes-from dbstroe2 -v $(pwd):/backup ubuntu bash -c "cd /dbdata && tar xvf /backup/backup.tar --strip 1"
tar: Removing leading `/' from member names
/dbdata/yun3.txt
/dbdata/aaa.txt
[root@hmm-docker ~]#
tmpfs
docker——存储配置与管理的更多相关文章
- paas架构之docker——容器进程管理
1.docker进程管理 docker的进程管理命令ps的用法基本和ubuntu系统的用法一致 1.1. 查看docker进程 sudo docker ps –a 1.2. 附着到容器上 Sudo d ...
- Docker多主机管理(八)--技术流ken
docker多主机管理 前面我们的实验环境中只有一个 docker host,所有的容器都是运行在这一个 host 上的.但在真正的环境中会有多个 host,容器在这些 host 中启动.运行.停止和 ...
- docker之镜像管理命令
一.docker image 镜像管理命令 指令 描述ls 列出本机镜像build 构建镜像来自Dockerfilehistory 查看镜像历史inspect 显示一个或多个镜像详细信息pull 从镜 ...
- Docker 的 Web 管理工具 DockerFly
Dockerfly是基于 Docker1.12+ (Docker API 1.24+) 开发出Docker 管理工具,提供里最基本的基于 Docker 的管理功能,目的是能够方便广大Docker初学者 ...
- Docker集群管理(一)—— 基础docker+swarm+shipyard
目的 学习docker的集群管理,摸索出高可用的docker微服务架构方案.本篇文章只初步的了解下swarm(docker新版已集成了swarm)的使用,了解docker的发现服务的基础方法(dock ...
- 基于zookeeper+mesos+marathon的docker集群管理平台
参考文档: mesos:http://mesos.apache.org/ mesosphere社区版:https://github.com/mesosphere/open-docs mesospher ...
- docker集群管理
docker集群管理 ps:docker machine docker swarm docker compose 在Docker Machine发布之前,你可能会遇到以下问题: ...
- docker容器日志管理(清理)
原文:docker容器日志管理(清理) 前言 在使用docker容器时候,其日志的管理是我们不得不考虑的事情.因为docker容器的日志文件会占据大量的磁盘空间.下面介绍的就是对docker容器日志的 ...
- docker集群管理之kubernetes
一.简介 kubernetes又叫做k8s,是Google开发的一款开源的docker集群管理工具,在这里对它的“发家史”,我不做过多的阐述,有时间大家可以自己去百度一下: 下面我要讲的就是容易混淆的 ...
- rabbitMQ安装docker版 /权限管理命令
1.进入docker hub镜像仓库地址:https://hub.docker.com/ 2.搜素rabbitMQ 查询镜像,可以看到多种类型,选择带有web页面的(managment) 3.拉取镜像 ...
随机推荐
- 关于mac使用figma以及企业微信3.1.18版本,CPU系统占用率飙升至70%
问题描述 使用一段时间正常,不知道是修改了什么设置,还是有什么软件冲突,导致cpu使用率极高 系统进程中有一个 kernel_task 占用了大量的cpu 并且该占用并不会消失,只要figma打开就会 ...
- 【.net】Error while trying to retrieve text for error ORA-06413
[.net]Error while trying to retrieve text for error ORA-06413 系统需要,有一个外挂系统使用的是.net,出了问题,所以部署环境查询代码 但 ...
- 节省 58% IT 成本,调用函数计算超过 30 亿次,石墨文档的 Serverless 实践
简介:石墨文档使用函数计算搭建文档实时编辑服务,由函数计算的智能调度系统自动分配执行环境,处理多用户同时编写文档带来的峰值负载,函数计算的动态扩缩容能力保障应用的可靠运行. 作者 | 金中茜 对石 ...
- Spring Cloud Stream 体系及原理介绍
简介: Spring Cloud Stream在 Spring Cloud 体系内用于构建高度可扩展的基于事件驱动的微服务,其目的是为了简化消息在 Spring Cloud 应用程序中的开发. 作者 ...
- Serverless 工程实践 | 自建 Apache OpenWhisk 平台
简介: OpenWhisk 是一个开源.无服务器的云平台,可以在运行时容器中通过执行扩展的代码响应各种事件,而无须用户关心相关的基础设施架构. OpenWhisk 简介 OpenWhisk 是基于云 ...
- ansible系列(28)--ansible的playbook异常处理
目录 1. playbook的异常处理 1.1 Playbook错误忽略 1.2 task执行失败强制调用handlers 1.3 控制Tasks报告状态为OK 1.4 changed_when检查任 ...
- 如何去掉WordPress分类目录url链接中的category,如何处理生成的作者链接
一个新网站需要结合SEO,才能做成一个优秀的网站, ◆◆◆ 关于WordPress的分类目录url中含有category的处理办法: 1,如果是新网站这些设置需要提前做,方便以后做SEO 1.修改固定 ...
- 用poi-tl导出word报告-支持表格文字刷色、背景刷色、表格合并单元格
官方教程地址:http://deepoove.com/poi-tl/ apache poi 入门示例教程:http://deepoove.com/poi-tl/apache-poi-guide.htm ...
- kettle使用3-增量同步(插入的时候判断数据是否存在,存在就更新,不存在就插入)
1.新建转换 2.在DB连接中,新建2个数据库连接 3.在输入中,新建:表输入 4.在输入中,新建:表输入 5.在输出中,新建:插入/更新 说明:更新字段: 是说更新目的表时候,哪些列更新,哪些不更新 ...
- 更改wsl中系统的安装位置
wsl默认安装位置是C盘,众所周知C盘总是不够用的,所以才有了把wsl的系统迁移到其它位置的需求.官网文档 首先查看所有分发版本 wsl -l --all -v 导出分发版为tar文件到D盘 wsl ...