[root@localhost ~]# docker infoContainers: 2Running: 0Paused: 0Stopped: 2Images: 2Server Version: 17.09.0-ceStorage Driver: overlayBacking Filesystem: xfsSupports d_type: trueLogging Driver: json-fileCgroup Driver: cgroupfsPlugins:Volume: localNetwork: bridge host macvlan null overlayLog: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslogSwarm: inactiveRuntimes: runcDefault Runtime: runcInit Binary: docker-initcontainerd version: 06b9cb35161009dcb7123345749fef02f7cea8e0runc version: 3f2f8b84a77f73d38244dd690525642a72156c64init version: 949e6faSecurity Options:seccompProfile: defaultKernel Version: 3.10.0-514.el7.x86_64Operating System: CentOS Linux 7 (Core)OSType: linuxArchitecture: x86_64CPUs: 1Total Memory: 992.7MiBName: localhost.localdomainID: N2QE:AAM2:MOUM:AHCW:3IBX:Z5OS:ACDT:6JN7:4LQ4:Z3QU:WTCZ:Y5T3Docker Root Dir: /var/lib/dockerDebug Mode (client): falseDebug Mode (server): falseRegistry: https://index.docker.io/v1/Experimental: falseInsecure Registries:127.0.0.0/8Live 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 infoContainers: 2Running: 0Paused: 0Stopped: 2Images: 2Server Version: 17.09.0-ceStorage Driver: overlayBacking Filesystem: xfsSupports d_type: trueLogging Driver: json-fileCgroup Driver: cgroupfsPlugins:Volume: localNetwork: bridge host macvlan null overlayLog: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslogSwarm: inactiveRuntimes: runcDefault Runtime: runcInit Binary: docker-initcontainerd version: 06b9cb35161009dcb7123345749fef02f7cea8e0runc version: 3f2f8b84a77f73d38244dd690525642a72156c64init version: 949e6faSecurity Options:seccompProfile: defaultKernel Version: 3.10.0-514.el7.x86_64Operating System: CentOS Linux 7 (Core)OSType: linuxArchitecture: x86_64CPUs: 1Total Memory: 992.7MiBName: localhost.localdomainID: N2QE:AAM2:MOUM:AHCW:3IBX:Z5OS:ACDT:6JN7:4LQ4:Z3QU:WTCZ:Y5T3Docker Root Dir: /data/dockerDebug Mode (client): falseDebug Mode (server): falseRegistry: https://index.docker.io/v1/Experimental: falseInsecure Registries:127.0.0.0/8Live Restore Enabled: false
可以看到 Docker Root Dir 已经指向 /data/docker
[root@localhost ~]# df -hFilesystem Size Used Avail Use% Mounted on/dev/sda2 7.8G 4.1G 3.8G 52% /devtmpfs 487M 0 487M 0% /devtmpfs 497M 0 497M 0% /dev/shmtmpfs 497M 6.6M 490M 2% /runtmpfs 497M 0 497M 0% /sys/fs/cgroup/dev/sda1 197M 93M 104M 48% /boottmpfs 100M 0 100M 0% /run/user/0overlay 7.8G 4.1G 3.8G 52% /data/docker/overlay/aa1ec9a6f30055da273ed53f42b50262ab3712fe2082b1c79a65bd860d34e585/mergedshm 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”
