[root@localhost ~]# docker info
Containers: 2
Running: 0
Paused: 0
Stopped: 2
Images: 2
Server Version: 17.09.0-ce
Storage Driver: overlay
Backing Filesystem: xfs
Supports d_type: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 06b9cb35161009dcb7123345749fef02f7cea8e0
runc version: 3f2f8b84a77f73d38244dd690525642a72156c64
init version: 949e6fa
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: 992.7MiB
Name: localhost.localdomain
ID: N2QE:AAM2:MOUM:AHCW:3IBX:Z5OS:ACDT:6JN7:4LQ4:Z3QU:WTCZ:Y5T3
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
在 Docker Root Dir 部分可以看到,容器默认存储在 /var/lib/docker 位置。
修改默认位置方法:
打开 /etc/docker/daemon.json 输入以下内容(如果没有找到就创建一个)
{
"graph":"/data/docker"
}
重启docker
[root@localhost ~]# systemctl restart docker
[root@localhost ~]# docker info
Containers: 2
Running: 0
Paused: 0
Stopped: 2
Images: 2
Server Version: 17.09.0-ce
Storage Driver: overlay
Backing Filesystem: xfs
Supports d_type: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 06b9cb35161009dcb7123345749fef02f7cea8e0
runc version: 3f2f8b84a77f73d38244dd690525642a72156c64
init version: 949e6fa
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: 992.7MiB
Name: localhost.localdomain
ID: N2QE:AAM2:MOUM:AHCW:3IBX:Z5OS:ACDT:6JN7:4LQ4:Z3QU:WTCZ:Y5T3
Docker Root Dir: /data/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
可以看到 Docker Root Dir 已经指向 /data/docker
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 7.8G 4.1G 3.8G 52% /
devtmpfs 487M 0 487M 0% /dev
tmpfs 497M 0 497M 0% /dev/shm
tmpfs 497M 6.6M 490M 2% /run
tmpfs 497M 0 497M 0% /sys/fs/cgroup
/dev/sda1 197M 93M 104M 48% /boot
tmpfs 100M 0 100M 0% /run/user/0
overlay 7.8G 4.1G 3.8G 52% /data/docker/overlay/aa1ec9a6f30055da273ed53f42b50262ab3712fe2082b1c79a65bd860d34e585/merged
shm 64M 0 64M 0% /data/docker/containers/fbab97285a08627c19ecbb5b6c59fe45ac72a48341f253ef51de82651fb1c461/shm
df 命令 overlay 这一行可以看出来,镜像的层在 /data/docker/overlay/ 这个目录下
关于 daemon.json 可以看下官网的说明
https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-configuration-file
打开之后搜索 “DAEMON CONFIGURATION FILE”