更新時間:2018-06-08 19:55:06html
Docker 的數據是經過聯合文件系統的方式存儲到磁盤上,當須要在機器上運行的容器或者鏡像的數量不斷增長時,有可能磁盤的大小再也不知足需求,這個時候就須要經過增長數據盤的方式,給 Docker的數據目錄可存儲的空間進行擴容。node
Docker默認的容器和鏡像數據存儲的目錄是在 /var/lib/docker 下,能夠經過 du 命令查看這個目錄目前佔用的磁盤的大小,例如:linux
du -h --max-depth=0 /var/lib/docker 7.9G /var/lib/docker
由於不少 Docker 的鏡像很大,因此可能幾個鏡像就佔用很大的磁盤空間,從而致使磁盤空間不足,經過爲 Docker 的數據目錄增長數據盤的方式,能夠知足繼續增長鏡像或容器的需求。docker
/dev/xvd*
或者 /dev/vd*
。根據 cd 命令肯定掛載點,IO 優化實例的掛載點是 /dev/vd*
。登陸到機器上,對剛纔掛載的磁盤進行格式化服務器
ls -l /dev/xvd*
或者 ls -l /dev/vd*
看到和剛纔記錄的一致的磁盤ID。mkfs.ext4
格式化磁盤,具體請參見 Linux 格式化和掛載數據盤,例如: root@iZbp16h1ijt5er5wempg4sZ:~# ls -l /dev/vd* brw-rw---- 1 root disk 253, 0 Jan 5 17:44 /dev/vda brw-rw---- 1 root disk 253, 1 Jan 5 17:44 /dev/vda1 brw-rw---- 1 root disk 253, 16 Jan 5 17:55 /dev/vdb root@iZbp16h1ijt5er5wempg4sZ:~# fdisk -S 56 /dev/vdb Welcome to fdisk (util-linux 2.27.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 0x44e128c4. Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-41943039, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): Created a new partition 1 of type 'Linux' and of size 20 GiB. Command (m for help): wq The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks. root@iZbp16h1ijt5er5wempg4sZ:~# ll /dev/vd* brw-rw---- 1 root disk 253, 0 Jan 5 17:44 /dev/vda brw-rw---- 1 root disk 253, 1 Jan 5 17:44 /dev/vda1 brw-rw---- 1 root disk 253, 16 Jan 5 17:58 /dev/vdb brw-rw---- 1 root disk 253, 17 Jan 5 17:58 /dev/vdb1 ##新增分區 root@iZbp16h1ijt5er5wempg4sZ:~# mkfs.ext4 /dev/vdb1 ##格式化 mke2fs 1.42.13 (17-May-2015) Creating filesystem with 5242624 4k blocks and 1310720 inodes Filesystem UUID: cef1625c-7533-4308-bc44-511580e3edc8 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done
移動 Docker 的數據到新的磁盤ide
啓動 Docker daemon,並檢查數據位置優化
root@iZbp16h1ijt5er5wempg4sZ:/# df -h Filesystem Size Used Avail Use% Mounted on udev 2.0G 0 2.0G 0% /dev tmpfs 396M 7.1M 389M 2% /run /dev/vda1 40G 2.7G 35G 8% / tmpfs 2.0G 476K 2.0G 1% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup tmpfs 396M 0 396M 0% /run/user/0 /dev/vdb1 20G 2.1G 17G 12% /var/lib/docker ##該目錄掛在到新的磁盤上 ....
restart:always
標籤的容器。