• docker 存储扩容和存放路径修改


     

    1.1 Docker 磁盘扩容

    默认情况下,物理机下创建的docker容器的空间是10G(虚拟机下创建的docker容器空间就是虚拟机的空间)。

    Docker容器动态扩展的优点:
    1)不需要修改docker配置,不需要重启docker服务;
    2)可以直接对运行中的容器进行动态扩展(只能增,无法缩);

    Docker容器动态扩展的条件:
    1)docker所在宿主机分区的格式必须是ext2、ext3、ext4、xfs;
    2)docker存储引擎必须是devicemapper

    [root@localhost ~]# docker exec -it test1 /bin/bash

    root@4f69d970a7b2:/usr/local/tomcat# cd

    root@4f69d970a7b2:~# df -HT

    Filesystem                                                                                          Type   Size  Used Avail Use% Mounted on

    /dev/mapper/docker-253:0-201995560-8b92c0e22cb3747dd4d5b97d8dde120757964a1dc0bcf4340831654f68532b20 xfs     22G  537M   21G   3% /

    tmpfs                                                                                               tmpfs   68M     0   68M   0% /dev

    tmpfs                                                                                               tmpfs  513M     0  513M   0% /sys/fs/cgroup

    /dev/mapper/centos-root                                                                             xfs     41G  2.1G   39G   6% /etc/hosts

    shm                                                                                                 tmpfs   68M     0   68M   0% /dev/shm

    tmpfs                                                                                               tmpfs  513M     0  513M   0% /proc/scsi

    tmpfs                                                                                               tmpfs  513M     0  513M   0% /sys/firmware

    使用dmsetup查看该文件扇区信息.下面命令结果中的第二个数字(即20971520)是设备的大小,表示有多少个 512-bytes 的扇区. 这个值略高于 10GB 的大小。

    [root@localhost ~]# dmsetup table /dev/mapper/docker-253:0-201995560-8b92c0e22cb3747dd4d5b97d8dde120757964a1dc0bcf4340831654f68532b20

    0 20971520 thin 253:2 21

    [root@localhost ~]# echo $((20*1024*1024*1024/512))

    41943040

    精简快照目标的一个神奇的特点是它不会限制卷的大小。当创建它的时候,一个精简的卷使用0个块,当开始往块里面写入的时候,它们会从共用的块池中进行分配。

    可以写0个块,或者是10亿个块,这个和精简快照目标没关系。文件系统的大小只和Device Mapper表有关系。

    只需要装载一个新的表,这个完全和之前的是一样的,但是有更多的扇区。仅此而已。

    [root@localhost ~]# echo 0 41943040 thin 253:2 21|dmsetup load /dev/mapper/docker-253:0-201995560-8b92c0e22cb3747dd4d5b97d8dde120757964a1dc0bcf4340831654f68532b20

    [root@localhost ~]# dmsetup resume /dev/mapper/docker-253:0-201995560-8b92c0e22cb3747dd4d5b97d8dde120757964a1dc0bcf4340831654f68532b20

    [root@localhost ~]# dmsetup table /dev/mapper/docker-253:0-201995560-8b92c0e22cb3747dd4d5b97d8dde120757964a1dc0bcf4340831654f68532b20

    0 41943040 thin 253:2 21

    更改文件系统大小,使变更生效

    centos6 ext4 文件系统使用resize2fs centos7 xfs使用 xfs_growfs

    [root@localhost ~]# xfs_growfs /dev/mapper/docker-253:0-201995560-8b92c0e22cb3747dd4d5b97d8dde120757964a1dc0bcf4340831654f68532b20

    meta-data=/dev/mapper/docker-253:0-201995560-8b92c0e22cb3747dd4d5b97d8dde120757964a1dc0bcf4340831654f68532b20 isize=256    agcount=16, agsize=163824 blks

             =                       sectsz=512   attr=2, projid32bit=1

             =                       crc=0        finobt=0

    data     =                       bsize=4096   blocks=2621184, imaxpct=25

             =                       sunit=16     swidth=16 blks

    naming   =version 2              bsize=4096   ascii-ci=0 ftype=0

    log      =internal               bsize=4096   blocks=2560, version=2

             =                       sectsz=512   sunit=16 blks, lazy-count=1

    realtime =none                   extsz=4096   blocks=0, rtextents=0

    data blocks changed from 2621184 to 5242880

    扩容后可能出现的问题:停止该容器后,无法重新启动-

    当容器扩容之后,由于dm认为设备块大小仍然为之前设置的初始大小,所以会发生无法起启动的情况,这时只要重新操作即可。

    必须要先启动一下,让其生成dm文件才能修改

    [root@localhost ~]# docker stop test1

    test1

    [root@localhost ~]# docker start test1

    Error response from daemon: devmapper: Error mounting '/dev/mapper/docker-253:0-201995560-8b92c0e22cb3747dd4d5b97d8dde120757964a1dc0bcf4340831654f68532b20' on '/var/lib/docker/devicemapper/mnt/8b92c0e22cb3747dd4d5b97d8dde120757964a1dc0bcf4340831654f68532b20': input/output error

    <5>[ 1466.086161] XFS (dm-4): Unmounting Filesystem

    <6>[ 1471.776965] attempt to access beyond end of device

    <6>[ 1471.776967] dm-4: rw=32, want=41943040, limit=20971520

    <4>[ 1471.776969] XFS (dm-4): last sector read failed

    Error: failed to start containers: test1

    [root@localhost ~]# echo 0 41943040 thin 253:2 21|dmsetup load /dev/mapper/docker-253:0-201995560-8b92c0e22cb3747dd4d5b97d8dde120757964a1dc0bcf4340831654f68532b20

    [root@localhost ~]# dmsetup resume /dev/mapper/docker-253:0-201995560-8b92c0e22cb3747dd4d5b97d8dde120757964a1dc0bcf4340831654f68532b20

    [root@localhost ~]# docker start test1

    test1

    1.2 Docker镜像和容器存放目录修改方法

    [root@localhost ~]# mv /var/lib/docker /var/lib/docker_bak

    [root@localhost ~]# mkdir -p /home/var/docker

    [root@localhost ~]# vim /usr/lib/systemd/system/docker.service

    [root@localhost ~]# cat /usr/lib/systemd/system/docker.service |grep ExecStart

    ExecStart=/usr/bin/dockerd --graph /home/var/docker

    [root@localhost ~]# systemctl start docker

    [root@localhost ~]# ls /home/var/docker/

    builder  containerd  containers  devicemapper  image  network  plugins  runtimes  swarm  tmp  trust  volumes

    [root@localhost ~]# rm -rf /home/var/docker/*

    [root@localhost ~]# mv /var/lib/docker_bak/* /home/var/docker/

    [root@localhost ~]# docker images

    REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

    ubuntu              16.04               a51debf7e1eb        6 days ago          116MB

    tomcat              latest              78b258e36eed        9 days ago          463MB

    [root@localhost ~]# docker ps -a

    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES

    4f69d970a7b2        tomcat:latest       "/bin/bash"         42 minutes ago      Exited (0) 7 minutes ago                       test1

    c6c2eed26cf5        ubuntu:16.04        "/bin/bash"         About an hour ago   Exited (0) 7 minutes ago                       test

    [root@localhost ~]# docker start test1

    Error response from daemon: devmapper: Error mounting '/dev/mapper/docker-253:0-201995560-8b92c0e22cb3747dd4d5b97d8dde120757964a1dc0bcf4340831654f68532b20' on '/home/var/docker/devicemapper/mnt/8b92c0e22cb3747dd4d5b97d8dde120757964a1dc0bcf4340831654f68532b20': input/output error

    <6>[ 3136.484691] attempt to access beyond end of device

    <6>[ 3136.484694] dm-3: rw=32, want=41943040, limit=20971520

    <4>[ 3136.484696] XFS (dm-3): last sector read failed

    Error: failed to start containers: test1

    [root@localhost ~]# echo 0 41943040 thin 253:2 21|dmsetup load /dev/mapper/docker-253:0-201995560-8b92c0e22cb3747dd4d5b97d8dde120757964a1dc0bcf4340831654f68532b20

    [root@localhost ~]# dmsetup resume /dev/mapper/docker-253:0-201995560-8b92c0e22cb3747dd4d5b97d8dde120757964a1dc0bcf4340831654f68532b20

    [root@localhost ~]# docker start test1

    test1

    参考:https://www.cnblogs.com/kevingrace/category/839227.html                                                                                        

  • 相关阅读:
    AndroidStudio 混淆打包
    android监听键盘
    Emoji字符检查与替换
    自定义Toast样式-两行文本居中显示
    强密码验证的正则表达式
    图片处理之-Bitmap.Config,jpeg压缩与大小
    Android App开之标注切图
    Android基础之CountDownTimer 倒计时类
    Android Handler Leak
    单目标跟踪CVPR 2018 ECO+
  • 原文地址:https://www.cnblogs.com/Honeycomb/p/10022200.html
Copyright © 2020-2023  润新知