from

    1. [root@localhost ~]# docker info
    2. Containers: 2
    3. Running: 0
    4. Paused: 0
    5. Stopped: 2
    6. Images: 2
    7. Server Version: 17.09.0-ce
    8. Storage Driver: overlay
    9. Backing Filesystem: xfs
    10. Supports d_type: true
    11. Logging Driver: json-file
    12. Cgroup Driver: cgroupfs
    13. Plugins:
    14. Volume: local
    15. Network: bridge host macvlan null overlay
    16. Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
    17. Swarm: inactive
    18. Runtimes: runc
    19. Default Runtime: runc
    20. Init Binary: docker-init
    21. containerd version: 06b9cb35161009dcb7123345749fef02f7cea8e0
    22. runc version: 3f2f8b84a77f73d38244dd690525642a72156c64
    23. init version: 949e6fa
    24. Security Options:
    25. seccomp
    26. Profile: default
    27. Kernel Version: 3.10.0-514.el7.x86_64
    28. Operating System: CentOS Linux 7 (Core)
    29. OSType: linux
    30. Architecture: x86_64
    31. CPUs: 1
    32. Total Memory: 992.7MiB
    33. Name: localhost.localdomain
    34. ID: N2QE:AAM2:MOUM:AHCW:3IBX:Z5OS:ACDT:6JN7:4LQ4:Z3QU:WTCZ:Y5T3
    35. Docker Root Dir: /var/lib/docker
    36. Debug Mode (client): false
    37. Debug Mode (server): false
    38. Registry: https://index.docker.io/v1/
    39. Experimental: false
    40. Insecure Registries:
    41. 127.0.0.0/8
    42. Live Restore Enabled: false

    在 Docker Root Dir 部分可以看到,容器默认存储在 /var/lib/docker 位置。
    修改默认位置方法:
    打开 /etc/docker/daemon.json 输入以下内容(如果没有找到就创建一个)

    1. {
    2. "graph":"/data/docker"
    3. }

    重启docker

    1. [root@localhost ~]# systemctl restart docker
    2. [root@localhost ~]# docker info
    3. Containers: 2
    4. Running: 0
    5. Paused: 0
    6. Stopped: 2
    7. Images: 2
    8. Server Version: 17.09.0-ce
    9. Storage Driver: overlay
    10. Backing Filesystem: xfs
    11. Supports d_type: true
    12. Logging Driver: json-file
    13. Cgroup Driver: cgroupfs
    14. Plugins:
    15. Volume: local
    16. Network: bridge host macvlan null overlay
    17. Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
    18. Swarm: inactive
    19. Runtimes: runc
    20. Default Runtime: runc
    21. Init Binary: docker-init
    22. containerd version: 06b9cb35161009dcb7123345749fef02f7cea8e0
    23. runc version: 3f2f8b84a77f73d38244dd690525642a72156c64
    24. init version: 949e6fa
    25. Security Options:
    26. seccomp
    27. Profile: default
    28. Kernel Version: 3.10.0-514.el7.x86_64
    29. Operating System: CentOS Linux 7 (Core)
    30. OSType: linux
    31. Architecture: x86_64
    32. CPUs: 1
    33. Total Memory: 992.7MiB
    34. Name: localhost.localdomain
    35. ID: N2QE:AAM2:MOUM:AHCW:3IBX:Z5OS:ACDT:6JN7:4LQ4:Z3QU:WTCZ:Y5T3
    36. Docker Root Dir: /data/docker
    37. Debug Mode (client): false
    38. Debug Mode (server): false
    39. Registry: https://index.docker.io/v1/
    40. Experimental: false
    41. Insecure Registries:
    42. 127.0.0.0/8
    43. Live Restore Enabled: false

    可以看到 Docker Root Dir 已经指向 /data/docker

    1. [root@localhost ~]# df -h
    2. Filesystem Size Used Avail Use% Mounted on
    3. /dev/sda2 7.8G 4.1G 3.8G 52% /
    4. devtmpfs 487M 0 487M 0% /dev
    5. tmpfs 497M 0 497M 0% /dev/shm
    6. tmpfs 497M 6.6M 490M 2% /run
    7. tmpfs 497M 0 497M 0% /sys/fs/cgroup
    8. /dev/sda1 197M 93M 104M 48% /boot
    9. tmpfs 100M 0 100M 0% /run/user/0
    10. overlay 7.8G 4.1G 3.8G 52% /data/docker/overlay/aa1ec9a6f30055da273ed53f42b50262ab3712fe2082b1c79a65bd860d34e585/merged
    11. 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”
    image.png