Docker安装后默认下载的位置在/var/lib/docker
,如果/var
分区没有独立分出来,Linux下默认是与/
根分区在一起。一般我们装Linux系统的时候,除了做邮件服务器外,都不会把/var分区独立分出来,而且/分区一般不会太大,比如我现在用的这台根分区50G的,在拉镜像的时候提示硬盘空间不足的问题,而其它分区还有很大空间。基于此情此景,我们都要把这个目录改一下
查看当前Docker目录位置
#展示当前docker的配置信息
docker info
-------------------------------------------------------------------
#在信息找到Docker Root Dir,对应的就是了,默认为:
Docker Root Dir: /var/lib/docker
几种改法
1、最简单也是最暴力的方式——修改 /etc/systemd/system/multi-user.target.wants/docker.service
sudo vim /etc/systemd/system/multi-user.target.wants/docker.service
-------------------------------------------------------------------
#找到ExecStart部分,在此行末尾添加--graph=你的目录,我的如下
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
--graph=/home/hellxz/docker-home
-------------------------------------------------------------------
#保存退出,接着让systemd重新读取下这些service等的配置
sudo systemctl daemon-reload
#重启docker服务
sudo systemctl restart docker
--graph=/path/to/path
可以替换成-g /path/to/path
效果等同
2、官方文档中的方式,修改 /etc/docker/daemon.json
{
"registry-mirrors": ["http://hub-mirror.c.163.com"],
"data-root": "/home/docker"
}
保存退出,重启docker服务
sudo systemctl restart docker
验证
查看 docker info
查看 Docker Root 来验证目录位置
[root@HNGC-SVR-QCCBigDataSvr-Dev2 docker]# docker info
Client:
Debug Mode: false
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 19.03.13
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host ipvlan 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: 8fba4e9a7d01810a393d5d25a3621dc101981175
runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-693.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 31.26GiB
Name: HNGC-SVR-QCCBigDataSvr-Dev2
ID: 6QOM:GCGS:F7NS:KOH4:SHLI:6RWQ:EHSA:YGMY:LG24:LS6S:MAVN:54HY
Docker Root Dir: /home/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Registry Mirrors:
http://hub-mirror.c.163.com/
Live Restore Enabled: false
相比上边的,镜像位置已经修改完毕。