centos 7环境下修改docker默认的存储位置

购买阿里云盘

挂载阿里云盘

  • 查看服务器硬盘情况
  1. [root@iZwz91xbt2dbgsvpm19vnqZ ~]# df -h
  2. Filesystem Size Used Avail Use% Mounted on
  3. devtmpfs 3.7G 0 3.7G 0% /dev
  4. tmpfs 3.7G 0 3.7G 0% /dev/shm
  5. tmpfs 3.7G 8.7M 3.7G 1% /run
  6. tmpfs 3.7G 0 3.7G 0% /sys/fs/cgroup
  7. /dev/vda1 40G 40G 13M 100% /
  8. overlay 40G 40G 13M 100% /var/lib/docker/overlay2/28185673f635d128480e28e641145700d7d4d761e62c6db47f7142c5e1d27d88/merged
  9. overlay 40G 40G 13M 100% /var/lib/docker/overlay2/ea31b8d60cee742344f1ca7848ff1b5b67fb1a5468f43a2066c9e0e91198085f/merged
  10. shm 64M 0 64M 0% /var/lib/docker/containers/75774f549b26379fc8c9c8d19464bfb61b64137f8257e73f4334e8075c014f57/moun
  11. shm 64M 0 64M 0% /var/lib/docker/containers/22b6fd8c98495bb65eba0fbf02618a8b4742ec5b75212c7e5cd5beec6cfd2a5c/moun
  12. tmpfs 746M 0 746M 0% /run/user/0
  • 查看硬盘情况
  1. [root@iZwz91xbt2dbgsvpm19vnqZ ~]# fdisk -l
  2. Disk /dev/vda: 40 GiB, 42949672960 bytes, 83886080 sectors
  3. Units: sectors of 1 * 512 = 512 bytes
  4. Sector size (logical/physical): 512 bytes / 512 bytes
  5. I/O size (minimum/optimal): 512 bytes / 512 bytes
  6. Disklabel type: dos
  7. Disk identifier: 0x951dd9ee
  8. Device Boot Start End Sectors Size Id Type
  9. /dev/vda1 * 2048 83886046 83883999 40G 83 Linux
  10. Disk /dev/vdb: 50 GiB, 53687091200 bytes, 104857600 sectors
  11. Units: sectors of 1 * 512 = 512 bytes
  12. Sector size (logical/physical): 512 bytes / 512 bytes
  13. I/O size (minimum/optimal): 512 bytes / 512 bytes
  • 分盘
  1. [root@iZwz91xbt2dbgsvpm19vnqZ ~]# fdisk -u /dev/vdb
  2. Welcome to fdisk (util-linux 2.32.1).
  3. Changes will remain in memory only, until you decide to write them.
  4. Be careful before using the write command.
  5. Device does not contain a recognized partition table.
  6. Created a new DOS disklabel with disk identifier 0xe97ce570.
  7. Command (m for help): n
  8. Partition type
  9. p primary (0 primary, 0 extended, 4 free)
  10. e extended (container for logical partitions)
  11. Select (default p): p
  12. Partition number (1-4, default 1):
  13. First sector (2048-104857599, default 2048):
  14. Last sector, +sectors or +size{K,M,G,T,P} (2048-104857599, default 104857599):
  15. Created a new partition 1 of type 'Linux' and of size 50 GiB.
  16. Command (m for help): wq
  17. The partition table has been altered.
  18. Calling ioctl() to re-read partition table.
  19. Syncing disks.
  • 再次查看硬盘情况
  1. [root@iZwz91xbt2dbgsvpm19vnqZ ~]# fdisk -l
  2. Disk /dev/vda: 40 GiB, 42949672960 bytes, 83886080 sectors
  3. Units: sectors of 1 * 512 = 512 bytes
  4. Sector size (logical/physical): 512 bytes / 512 bytes
  5. I/O size (minimum/optimal): 512 bytes / 512 bytes
  6. Disklabel type: dos
  7. Disk identifier: 0x951dd9ee
  8. Device Boot Start End Sectors Size Id Type
  9. /dev/vda1 * 2048 83886046 83883999 40G 83 Linux
  10. Disk /dev/vdb: 50 GiB, 53687091200 bytes, 104857600 sectors
  11. Units: sectors of 1 * 512 = 512 bytes
  12. Sector size (logical/physical): 512 bytes / 512 bytes
  13. I/O size (minimum/optimal): 512 bytes / 512 bytes
  14. Disklabel type: dos
  15. Disk identifier: 0xe97ce570
  16. Device Boot Start End Sectors Size Id Type
  17. /dev/vdb1 2048 104857599 104855552 50G 83 Linux
  • 格式化分区
  1. [root@iZwz91xbt2dbgsvpm19vnqZ ~]# mkfs.ext4 /dev/vdb1
  2. mke2fs 1.44.6 (5-Mar-2019)
  3. Creating filesystem with 13106944 4k blocks and 3276800 inodes
  4. Filesystem UUID: b98c6d12-6c19-44d4-8648-9d2ae8d6f1d7
  5. Superblock backups stored on blocks:
  6. 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
  7. 4096000, 7962624, 11239424
  8. Allocating group tables: done
  9. Writing inode tables: done
  10. Creating journal (65536 blocks): done
  11. Writing superblocks and filesystem accounting information: done
  • 挂载
  1. [root@iZwz91xbt2dbgsvpm19vnqZ ~]# mount /dev/vdb1 /mnt
  • 再次查看硬盘
  1. [root@iZwz91xbt2dbgsvpm19vnqZ ~]# df -h
  2. Filesystem Size Used Avail Use% Mounted on
  3. devtmpfs 3.7G 0 3.7G 0% /dev
  4. tmpfs 3.7G 0 3.7G 0% /dev/shm
  5. tmpfs 3.7G 708K 3.7G 1% /run
  6. tmpfs 3.7G 0 3.7G 0% /sys/fs/cgroup
  7. /dev/vda1 40G 40G 451M 99% /
  8. overlay 40G 40G 451M 99% /var/lib/docker/overlay2/28185673f635d128480e28e641145700d7d4d761e62c6db47f7142c5e1d27d88/merged
  9. overlay 40G 40G 451M 99% /var/lib/docker/overlay2/ea31b8d60cee742344f1ca7848ff1b5b67fb1a5468f43a2066c9e0e91198085f/merged
  10. shm 64M 0 64M 0% /var/lib/docker/containers/75774f549b26379fc8c9c8d19464bfb61b64137f8257e73f4334e8075c014f57/mounts/shm
  11. shm 64M 0 64M 0% /var/lib/docker/containers/22b6fd8c98495bb65eba0fbf02618a8b4742ec5b75212c7e5cd5beec6cfd2a5c/mounts/shm
  12. tmpfs 746M 0 746M 0% /run/user/0
  13. overlay 40G 40G 451M 99% /var/lib/docker/overlay2/450cd9115a3c4155e41aab56365f352e818bdc5902d006f13a36d03422e6678d/merged
  14. shm 64M 0 64M 0% /var/lib/docker/containers/88d72ca9805ad41134d207095977ec0aa7416fbfd44183212ea22fc6318827fc/mounts/shm
  15. /dev/vdb1 49G 53M 47G 1% /mnt

https://blog.51cto.com/jxzhfei/2308206

  1. [root@iZwz91xbt2dbgsvpm19vnqZ ~]# mkdir -p /mnt/docker/var/lib
  2. [root@iZwz91xbt2dbgsvpm19vnqZ ~]# ls /mnt/
  3. docker lost+found
  4. [root@iZwz91xbt2dbgsvpm19vnqZ ~]# systemctl stop docker
  5. cd /var/li[root@iZwz91xbt2dbgsvpm19vnqZ ~]# cd /var/lib/
  6. [root@iZwz91xbt2dbgsvpm19vnqZ lib]# mv docker /mnt/docker/var/lib/
  7. [root@iZwz91xbt2dbgsvpm19vnqZ lib]# ln -s /mnt/docker/var/lib/docker/ /var/lib/docker
  8. [root@iZwz91xbt2dbgsvpm19vnqZ lib]# systemctl start docker