為Docker掛載數(shù)據(jù)盤
步驟
- service docker stop
停掉docker服務(wù)
- mv /var/lib/docker /var/lib/docker_data
備份下docker目錄下的內(nèi)容
- df -h
用來查看磁盤的掛載和使用情況啄枕,此時數(shù)據(jù)盤未能掛載赃梧,所以沒有顯示
- fdisk -l
查看硬盤情況迄薄,可見有一個vdb硬盤未掛載
- fdisk /dev/vdb
開始分區(qū)
Command (m for help): m
--輸入m查看幫助:指令提示
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): n
--添加新分區(qū)
Command action
e extended
p primary partition (1-4)
p
--輸入p添加主分區(qū)
Partition number (1-4): 1
--填寫分區(qū)號
First cylinder (1-11748, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-11748, default 11748):
Using default value 11748
Command (m for help): p
--打印分區(qū)列表
Disk /dev/sdb: 96.6 GB, 96636764160 bytes
255 heads, 63 sectors/track, 11748 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 11748 94365778+ 83 Linux
Command (m for help): w
--保存退出
The partition table has been altered!
ps:如果要多個分區(qū)最后一步不用w,繼續(xù)n重復(fù)上述操作,最后w
- fdisk -l
此時可見剛剛的分區(qū)灵疮。 假設(shè): /dev/vdb1和/dev/vdb2
- mke2fs -t ext4 /dev/vdb1
為分區(qū)指定文件系統(tǒng)
- mkdir /var/lib/docker
創(chuàng)建空目錄
- mount /dev/vdb1 /var/lib/docker
掛載至docker目錄
- mv /var/lib/docker_data/* /var/lib/docker/
將之前備份的內(nèi)容轉(zhuǎn)移至原目錄
- service docker start
啟動docker服務(wù)
- docker ps
查看啟動的容器