centos 7环境下修改docker默认的存储位置
购买阿里云盘
挂载阿里云盘
- 查看服务器硬盘情况
[root@iZwz91xbt2dbgsvpm19vnqZ ~]# df -hFilesystem Size Used Avail Use% Mounted ondevtmpfs 3.7G 0 3.7G 0% /devtmpfs 3.7G 0 3.7G 0% /dev/shmtmpfs 3.7G 8.7M 3.7G 1% /runtmpfs 3.7G 0 3.7G 0% /sys/fs/cgroup/dev/vda1 40G 40G 13M 100% /overlay 40G 40G 13M 100% /var/lib/docker/overlay2/28185673f635d128480e28e641145700d7d4d761e62c6db47f7142c5e1d27d88/mergedoverlay 40G 40G 13M 100% /var/lib/docker/overlay2/ea31b8d60cee742344f1ca7848ff1b5b67fb1a5468f43a2066c9e0e91198085f/mergedshm 64M 0 64M 0% /var/lib/docker/containers/75774f549b26379fc8c9c8d19464bfb61b64137f8257e73f4334e8075c014f57/mounshm 64M 0 64M 0% /var/lib/docker/containers/22b6fd8c98495bb65eba0fbf02618a8b4742ec5b75212c7e5cd5beec6cfd2a5c/mountmpfs 746M 0 746M 0% /run/user/0
- 查看硬盘情况
[root@iZwz91xbt2dbgsvpm19vnqZ ~]# fdisk -lDisk /dev/vda: 40 GiB, 42949672960 bytes, 83886080 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x951dd9eeDevice Boot Start End Sectors Size Id Type/dev/vda1 * 2048 83886046 83883999 40G 83 LinuxDisk /dev/vdb: 50 GiB, 53687091200 bytes, 104857600 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytes
- 分盘
[root@iZwz91xbt2dbgsvpm19vnqZ ~]# fdisk -u /dev/vdbWelcome to fdisk (util-linux 2.32.1).Changes will remain in memory only, until you decide to write them.Be careful before using the write command.Device does not contain a recognized partition table.Created a new DOS disklabel with disk identifier 0xe97ce570.Command (m for help): nPartition typep primary (0 primary, 0 extended, 4 free)e extended (container for logical partitions)Select (default p): pPartition number (1-4, default 1):First sector (2048-104857599, default 2048):Last sector, +sectors or +size{K,M,G,T,P} (2048-104857599, default 104857599):Created a new partition 1 of type 'Linux' and of size 50 GiB.Command (m for help): wqThe partition table has been altered.Calling ioctl() to re-read partition table.Syncing disks.
- 再次查看硬盘情况
[root@iZwz91xbt2dbgsvpm19vnqZ ~]# fdisk -lDisk /dev/vda: 40 GiB, 42949672960 bytes, 83886080 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x951dd9eeDevice Boot Start End Sectors Size Id Type/dev/vda1 * 2048 83886046 83883999 40G 83 LinuxDisk /dev/vdb: 50 GiB, 53687091200 bytes, 104857600 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0xe97ce570Device Boot Start End Sectors Size Id Type/dev/vdb1 2048 104857599 104855552 50G 83 Linux
- 格式化分区
[root@iZwz91xbt2dbgsvpm19vnqZ ~]# mkfs.ext4 /dev/vdb1mke2fs 1.44.6 (5-Mar-2019)Creating filesystem with 13106944 4k blocks and 3276800 inodesFilesystem UUID: b98c6d12-6c19-44d4-8648-9d2ae8d6f1d7Superblock backups stored on blocks:32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,4096000, 7962624, 11239424Allocating group tables: doneWriting inode tables: doneCreating journal (65536 blocks): doneWriting superblocks and filesystem accounting information: done
- 挂载
[root@iZwz91xbt2dbgsvpm19vnqZ ~]# mount /dev/vdb1 /mnt
- 再次查看硬盘
[root@iZwz91xbt2dbgsvpm19vnqZ ~]# df -hFilesystem Size Used Avail Use% Mounted ondevtmpfs 3.7G 0 3.7G 0% /devtmpfs 3.7G 0 3.7G 0% /dev/shmtmpfs 3.7G 708K 3.7G 1% /runtmpfs 3.7G 0 3.7G 0% /sys/fs/cgroup/dev/vda1 40G 40G 451M 99% /overlay 40G 40G 451M 99% /var/lib/docker/overlay2/28185673f635d128480e28e641145700d7d4d761e62c6db47f7142c5e1d27d88/mergedoverlay 40G 40G 451M 99% /var/lib/docker/overlay2/ea31b8d60cee742344f1ca7848ff1b5b67fb1a5468f43a2066c9e0e91198085f/mergedshm 64M 0 64M 0% /var/lib/docker/containers/75774f549b26379fc8c9c8d19464bfb61b64137f8257e73f4334e8075c014f57/mounts/shmshm 64M 0 64M 0% /var/lib/docker/containers/22b6fd8c98495bb65eba0fbf02618a8b4742ec5b75212c7e5cd5beec6cfd2a5c/mounts/shmtmpfs 746M 0 746M 0% /run/user/0overlay 40G 40G 451M 99% /var/lib/docker/overlay2/450cd9115a3c4155e41aab56365f352e818bdc5902d006f13a36d03422e6678d/mergedshm 64M 0 64M 0% /var/lib/docker/containers/88d72ca9805ad41134d207095977ec0aa7416fbfd44183212ea22fc6318827fc/mounts/shm/dev/vdb1 49G 53M 47G 1% /mnt
https://blog.51cto.com/jxzhfei/2308206
[root@iZwz91xbt2dbgsvpm19vnqZ ~]# mkdir -p /mnt/docker/var/lib[root@iZwz91xbt2dbgsvpm19vnqZ ~]# ls /mnt/docker lost+found[root@iZwz91xbt2dbgsvpm19vnqZ ~]# systemctl stop dockercd /var/li[root@iZwz91xbt2dbgsvpm19vnqZ ~]# cd /var/lib/[root@iZwz91xbt2dbgsvpm19vnqZ lib]# mv docker /mnt/docker/var/lib/[root@iZwz91xbt2dbgsvpm19vnqZ lib]# ln -s /mnt/docker/var/lib/docker/ /var/lib/docker[root@iZwz91xbt2dbgsvpm19vnqZ lib]# systemctl start docker
