本文被帮忙文档:
- 链接 1
- 链接 2
CentOS7 批改 Docker 容器和镜像默认存储地位
通常,当你开始应用 docker 时,咱们并不太关怀 Docker 用于存储镜像和容器的默认目录。当应用 Docker 进行更多试验时,Docker 开始占用大量的空间时,你不得不按下紧急按钮。所以当初是时候把故障排除放在如何扭转 docker 的默认存储地位了
在试图扭转 Docker 的默认存储地位时,咱们必须晓得一些重要的信息。
docker 以后应用的默认存储地位
docker 以后应用的存储驱动程序
镜像和容器要寄存的新存储空间
Docker 默认的地位在 /var/lib/docker, 以后所有的镜像、容器都存储在这儿。如果你有任何在运行的容器,进行这些容器,并确保没有容器在运行,而后运行以下命令,确定以后 Docker 应用的存储驱动。
1、查看 docker 以后信息
注:此处须要留神 docker 的两个信息:
- Storage Driver: overlay2 以后 Docker 应用的存储驱动
- Docker Root Dir: /var/lib/docker 以后 docker 应用的数据目录
docker info
[root@localhost ~]# docker info
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 18.09.6
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: bb71b10fd8f58240ca47fbb579b9d1028eea7c84
runc version: 2b18fe1d885ee5083ef9f0838fee39b62d653e30
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-514.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 976.5MiB
Name: localhost.localdomain
ID: 3EGY:424H:ER2C:CBQ7:KUD5:SFRJ:TVDK:XV4Y:AFYJ:SOOL:7OM6:65K5
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
Product License: Community Engine
2、进行 docker 服务
systemctl stop docker
3、批改 docker 服务启动文件
[root@localhost ~]# vim /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --graph=/mnt/docker
留神:
- 原配置放弃不变,增加 –graph=/mnt/docker,/mnt/docker 是新的存储地位
-
以下两个文件均可批改 docker 配置:
/etc/systemd/system/multi-user.target.wants/docker.service /usr/lib/systemd/system/docker.service
4、将原先目录下所有的文件和目录拷贝到新目录下
[root@localhost mnt]# cp -rf /var/lib/docker/* /mnt/docker/
[root@localhost docker]# pwd
/mnt/docker
[root@localhost docker]# ls
builder buildkit containers image network overlay2 plugins runtimes swarm tmp trust volumes
5、从新加载配置并启动
[root@localhost docker]# systemctl daemon-reload
[root@localhost docker]# systemctl start docker
6、查看 docker 信息
[root@localhost docker]# docker info
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 18.09.6
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: bb71b10fd8f58240ca47fbb579b9d1028eea7c84
runc version: 2b18fe1d885ee5083ef9f0838fee39b62d653e30
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-514.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 976.5MiB
Name: localhost.localdomain
ID: 3EGY:424H:ER2C:CBQ7:KUD5:SFRJ:TVDK:XV4Y:AFYJ:SOOL:7OM6:65K5
Docker Root Dir: /mnt/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
Product License: Community Engine
注:
查看 ==Docker Root Dir: /mnt/docker== 信息可看到,docker 服务存储地位已批改