为Docker挂载数据盘
步骤
- service docker stop
停掉docker服务
- mv /var/lib/docker /var/lib/docker_data
备份下docker目录下的内容
- df -h
用来查看磁盘的挂载和使用情况,此时数据盘未能挂载,所以没有显示
- fdisk -l
查看硬盘情况,可见有一个vdb硬盘未挂载
- fdisk /dev/vdb
开始分区
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
--添加新分区
Command action
e extended
p primary partition (1-4)
p
--输入p添加主分区
Partition number (1-4): 1
--填写分区号
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
--打印分区列表
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:如果要多个分区最后一步不用w,继续n重复上述操作,最后w
- fdisk -l
此时可见刚刚的分区。 假设: /dev/vdb1和/dev/vdb2
- mke2fs -t ext4 /dev/vdb1
为分区指定文件系统
- mkdir /var/lib/docker
创建空目录
- mount /dev/vdb1 /var/lib/docker
挂载至docker目录
- mv /var/lib/docker_data/* /var/lib/docker/
将之前备份的内容转移至原目录
- service docker start
启动docker服务
- docker ps
查看启动的容器
网友评论