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: /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 位置。linux

修改默認位置方法:docker

打開 /etc/docker/daemon.json 輸入如下內容(若是沒有找到就建立一個)json

{
    "graph":"/data/docker"
}

重啓dockerbash

[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/dockerdom

[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/ 這個目錄下3d

 

關於 daemon.json 能夠看下官網的說明rest

https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-configuration-filecode

打開以後搜索 "DAEMON CONFIGURATION FILE"server

相關文章
相關標籤/搜索