Post

docker数据迁移

docker数据迁移

案例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
0 17:10:28 192.168.10.233:/mnt/mydata/kk $ df -h
文件系统               容量  已用  可用 已用% 挂载点
devtmpfs                16G     0   16G    0% /dev
tmpfs                   16G   12K   16G    1% /dev/shm
tmpfs                   16G  1.6G   15G   10% /run
tmpfs                   16G     0   16G    0% /sys/fs/cgroup
/dev/vda1               80G   80G  245M  100% /
/dev/mapper/myvg-mylv  985G   21G  914G    3% /mnt/mydata
tmpfs                  3.2G     0  3.2G    0% /run/user/0
overlay                 80G   80G  245M  100% /var/lib/docker/overlay2/6bd1463aa64ed957baa913c70a0e250fa424ef99e10c6c00a9e0185ec414b501/merged
overlay                 80G   80G  245M  100% /var/lib/docker/overlay2/4b60780f9adffdc349e9860e3226ba32e9639df040e1906dbad9b4762e8a5d7d/merged
overlay                 80G   80G  245M  100% /var/lib/docker/overlay2/7b702c565deb0b517fff7e30945e1e775a08a7c67754bb78a074639fa0ba2a80/merged
overlay                 80G   80G  245M  100% /var/lib/docker/overlay2/c0ebf34c9953d2a918469e33e70953348e81db99d253d85e429a5d269a86054a/merged
overlay                 80G   80G  245M  100% /var/lib/docker/overlay2/108d488a8b57577df3d9d25ec3dd5c56c960f700019574ece27ec354ed836506/merged
overlay                 80G   80G  245M  100% /var/lib/docker/overlay2/88997e086990f8f4add08077b108ac69e88f705e2a88a2161ef0d2a4562c1f16/merged
overlay                 80G   80G  245M  100% /var/lib/docker/overlay2/efd91ab7c2c8f8c0381541ee807fee8de23645e4aca9087765bdb2d0a3778317/merged
overlay                 80G   80G  245M  100% /var/lib/docker/overlay2/3e46cda2077f25a82fb174a64ef949142c649aca8169d82786632249a2dea196/merged
overlay                 80G   80G  245M  100% /var/lib/docker/overlay2/88761124b50dca4ec9e169b438a5ce3c28a023aabfa487d8aa5595c23fbd9f4a/merged
overlay                 80G   80G  245M  100% /var/lib/docker/overlay2/121916c52252654e00f16d93507944ed028579b654fdc57834f7cb9347155977/merged
overlay                 80G   80G  245M  100% /var/lib/docker/overlay2/984d917c01a9838980084a1031244b91a4e1a6dbe3acca06f6a5127462064bb4/merged
overlay                 80G   80G  245M  100% /var/lib/docker/overlay2/c14a7de37c4370533e846d5bce5d04c760ac72c64c4ba69dbd61470adc7b7952/merged
overlay                 80G   80G  245M  100% /var/lib/docker/overlay2/b60153e3c8785e9e36e35d7074c9fb2fd8170fa0b7b18a43f05bbf1b8a277054/merged
overlay                 80G   80G  245M  100% /var/lib/docker/overlay2/a788a1f62e990963883ee0eac23e6a5f74626df17e8bf7bad97f376523f8225e/merged
overlay                 80G   80G  245M  100% /var/lib/docker/overlay2/c7c0865b8eee4787f872f6eaf21e70cc15d03afcb2eeb586eed7da9992a3c3b5/merged
overlay                 80G   80G  245M  100% /var/lib/docker/overlay2/1ac5a2ac719ece89af2df87bcd98e3ea9b0ef490024015be574da2c81eeb7230/merged

原来的环境

验证数据迁移

从你给出的信息中,我们可以看到 /dev/vda1 的 80G 容量已经使用了100%,而磁盘 /dev/mapper/myvg-mylv 还有大量的可用空间。下面是将磁盘空间增加到 /var/lib/docker 的一种可能的方式。

首先,如果你有一些可以删除的文件或者旧的docker镜像和容器,那么删除它们可以获得一些空间。

其次,你应该在大量的可用磁盘 /dev/mapper/myvg-mylv 上创建一个新的目录,例如/mnt/mydata/docker

然后,你可以停止正在运行的Docker守护进程:

1
systemctl stop docker

接着,将原来的 /var/lib/docker 目录下的内容移动到新的目录:

1
mv /var/lib/docker/ /mnt/mydata/docker

然后,建立符号链接,使得 /var/lib/docker 点向新的位置:

1
ln -s /mnt/mydata/docker /var/lib/docker

最后,你可以重新启动 Docker 守护进程查看效果:

1
systemctl start docker

如果一切顺利,你应该会在 /var/lib/docker 上获得更多的可用空间,而不影响现有的功能。你可以使用 df -h 命令确认 Docker 是否已经开始使用新的磁盘空间。

这种方法非常直接,但是要注意,它实际上并没有真正地增加你的 / 分区的空间,而只是为Docker提供了更多的存储空间。如果在 / 分区上的其他目录需要更多的空间,你可能需要寻找其他的方法来解决你的问题。

harbor的镜像会重新创建, harbor中原来的镜像不受影响

迁移后的效果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
0 18:02:48 192.168.10.233:/opt/harbor $ df -h
文件系统               容量  已用  可用 已用% 挂载点
devtmpfs                16G     0   16G    0% /dev
tmpfs                   16G   12K   16G    1% /dev/shm
tmpfs                   16G  1.6G   15G   11% /run
tmpfs                   16G     0   16G    0% /sys/fs/cgroup
/dev/vda1               80G   32G   49G   40% /
/dev/mapper/myvg-mylv  985G   72G  863G    8% /mnt/mydata
tmpfs                  3.2G     0  3.2G    0% /run/user/0
overlay                 80G   32G   49G   40% /var/lib/docker/overlay2/2711e098d0eb952d8bc34bac1f75fcd3c7ad90272348bb1d7c27f4d318ef3f2d/merged
overlay                 80G   32G   49G   40% /var/lib/docker/overlay2/3d4bde88ed210bc796f51bffe199d67f50fed420902aa6428ec48bd789010de8/merged
overlay                 80G   32G   49G   40% /var/lib/docker/overlay2/969517abb7e183b58198257cc47c378fd2c441b700cda7d9c14690c5fad61a50/merged
overlay                 80G   32G   49G   40% /var/lib/docker/overlay2/3579a8617effa21fbd25e2c682863a757e1cd0efecad5bdd60e14a314c2fc80f/merged
overlay                 80G   32G   49G   40% /var/lib/docker/overlay2/734bedc474561df0f031e6020ba7850ed5bdb8bb62a69f2b3c61a03f32dbcb7b/merged
overlay                 80G   32G   49G   40% /var/lib/docker/overlay2/82018b7c7276bbf24d24d4a33adc90d9a92c2fcae29bc9a85036f191dfe0c473/merged
overlay                 80G   32G   49G   40% /var/lib/docker/overlay2/8e660266865424cd6c68b17c77e828965dd530714d39718c6dcb1474a8d6ec65/merged
overlay                 80G   32G   49G   40% /var/lib/docker/overlay2/63078ae5512936f8b1754d8a42635d9972655eb95536bfe4e0559d780c283f1e/merged
overlay                 80G   32G   49G   40% /var/lib/docker/overlay2/20aafe257ba68ce5c37f293b50260b535780dd0cf9bbe6526cec50241dda1c2b/merged
overlay                 80G   32G   49G   40% /var/lib/docker/overlay2/0e715ceb1033d70b698327594b6b217ce88e71101ad84039379a17153ef44e3f/merged
overlay                 80G   32G   49G   40% /var/lib/docker/overlay2/818648a257eb079c364b16e8682f2edd05cbf9d2cf05b0eb7a8a78995a1c106d/merged
overlay                 80G   32G   49G   40% /var/lib/docker/overlay2/cdfb7db7d1b62872a7f7cce0c3ceec81096c46b941c9800661d883b98d086455/merged
overlay                 80G   32G   49G   40% /var/lib/docker/overlay2/96a7c82724ddc170ffa72c265a221705bc23fa240d4365ab011a34e10ddf3015/merged

完整流程

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
[root@harbor harbor]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 7.8G     0  7.8G   0% /dev
tmpfs                    7.8G     0  7.8G   0% /dev/shm
tmpfs                    7.8G  3.1M  7.8G   1% /run
tmpfs                    7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/mapper/centos-root  100G   14G   87G  14% /
/dev/mapper/centos-home   47G   39M   47G   1% /home
/dev/sdb1                296G   65M  281G   1% /data
/dev/sda1               1014M  180M  835M  18% /boot
tmpfs                    1.6G   12K  1.6G   1% /run/user/42
tmpfs                    1.6G     0  1.6G   0% /run/user/0
overlay                  100G   14G   87G  14% /var/lib/docker/overlay2/3802ff8254fdfa35477424da06eb85e84429d3e0e769052e8d45d25477206ac1/merged
overlay                  100G   14G   87G  14% /var/lib/docker/overlay2/d1203f90fc57b1d2c3164254bb41f35f9ba51ae219308da28107c390c978d20f/merged
overlay                  100G   14G   87G  14% /var/lib/docker/overlay2/08bc06ec646dfacc0fe4535a47477a191da99f7bce9390584c20ca0b4fda3699/merged
overlay                  100G   14G   87G  14% /var/lib/docker/overlay2/63c4690c7558a3a6d7de62efeaac3eb247fd547ff6b51231da690420c932c5a2/merged
overlay                  100G   14G   87G  14% /var/lib/docker/overlay2/06b026d3f714e78ba2f00e5d7e883422cffce0158f95ae5e196558ca26512664/merged
overlay                  100G   14G   87G  14% /var/lib/docker/overlay2/d39343418aab34bd5a0cae9727bd330bdf42f637e842326ae04c4de5f71717f5/merged
overlay                  100G   14G   87G  14% /var/lib/docker/overlay2/74577390e5a77722184ff44357ba7265d0a5393e26d88d0f2fbc130b80ad1e3c/merged
overlay                  100G   14G   87G  14% /var/lib/docker/overlay2/8d55c432fec1dce19985559ec44286162b5728faef20645adbeb55c8dc163711/merged
overlay                  100G   14G   87G  14% /var/lib/docker/overlay2/dff3b4bdc5b2a50658aa35d7672f63f65cdf51046e0ffd36ad47bdf7ef149b38/merged
overlay                  100G   14G   87G  14% /var/lib/docker/overlay2/984aa26285d22ac4a9e8181cb6ed868bd2490480cf37d216892f807806d785dd/merged
overlay                  100G   14G   87G  14% /var/lib/docker/overlay2/f20957d3d60fb19d986c92ac4b9603b5ec95f07a2070a591af05a5862ee18a50/merged
overlay                  100G   14G   87G  14% /var/lib/docker/overlay2/42465375f0e86bce6f84d51661123dadc1910defcc1cc5100f6e52923c7b21cc/merged
overlay                  100G   14G   87G  14% /var/lib/docker/overlay2/1f0defb4ce3380b1d6c1c6df4d7a9905a1084d2c49b9dc691e4ec78ea97ef275/merged

[root@harbor harbor]# systemctl stop docker
[root@harbor harbor]#

[root@harbor harbor]# mv /var/lib/docker/ /data
[root@harbor harbor]#
[root@harbor harbor]#


[root@harbor harbor]# ls -lt /var/lib/
total 12
drwx------.  2 root           root             29 Jun  7 11:11 rsyslog
lrwxrwxrwx   1 root           root             13 Jun  7 11:11 docker -> /data/docker/
drwx------.  2 root           root           4096 Jun  7 11:09 NetworkManager
drwx--x--x   3 root           root             43 Jun  7 10:01 containerd
drwxr-x---.  2 root           slocate          24 Jun  7 03:45 mlocate
drwxr-xr-x.  2 root           root             30 Jun  7 03:45 logrotate
drwxr-xr-x.  2 unbound        unbound          22 Jun  7 00:00 unbound
drwxr-xr-x.  2 root           root             29 Nov  9  2023 xkb
drwxrwx--T.  7 gdm            gdm              97 Nov  9  2023 gdm
drwxr-xr-x.  4 root           root             63 Nov  9  2023 net-snmp
drwxr-xr-x.  2 root           root           4096 Nov  9  2023 rpm
drwxr-xr-x.  4 root           root             55 Nov  9  2023 gssproxy
drwxr-xr-x   4 root           root             35 Aug 16  2023 cni
drwx------   8 root           root            208 Aug 16  2023 kubelet
drwxr-xr-x.  6 root           root             80 Aug 16  2023 yum
drwxr-xr-x   2 kube           root             33 Sep 28  2022 calico
drwxr-xr-x.  5 root           root            105 Sep 22  2022 nfs
drwxr-xr-x.  2 chrony         chrony           19 Sep 22  2022 chrony
drwxr-xr-x.  2 root           root             52 Sep 22  2022 PackageKit
drwxr-xr-x   2 haproxy        haproxy           6 Jun 10  2021 haproxy
drwxr-xr-x.  3 root           root             39 Mar 16  2021 fwupd
drwxr-xr-x.  3 root           root             19 Mar 15  2021 rpm-state
drwxr-xr-x.  2 root           root           4096 Mar 15  2021 alternatives
drwxr-xr-x.  9 root           root            106 Mar 15  2021 libvirt
drwxr-xr-x.  3 root           root             34 Feb  5  2021 flatpak
drwxr-xr-x.  5 root           root             70 Feb  3  2021 systemd
drwxr-xr-x. 10 root           root            120 Feb  3  2021 sss
drwxr-xr-x.  2 root           root              6 Feb  3  2021 tuned
drwxr-xr-x.  2 root           root              6 Jan 22  2021 dnsmasq
drwxr-xr-x.  4 root           root             53 Dec 16  2020 samba
drwx------.  2 pulse          pulse             6 Dec 16  2020 pulse
drwxr-xr-x.  8 root           root             90 Dec 16  2020 iscsi
drwxr-xr-x.  4 root           root             35 Nov 17  2020 stateless
drwxr-xr-x.  4 root           root             35 Oct  5  2020 ipa-client
drwxr-xr-x.  2 root           root             27 Oct  2  2020 plymouth
drwxr-xr-x.  2 root           root              6 Oct  2  2020 dhclient
drwxr-xr-x.  2 root           root              6 Sep 30  2020 initramfs
drwxr-xr-x.  2 root           root             24 Sep 30  2020 dbus
drwxr-xr-x.  5 root           root             46 Sep 30  2020 certmonger
drwxr-xr-x.  2 root           root              6 Sep 30  2020 bluetooth
drwxr-xr-x.  2 root           root              6 Jul 29  2020 fwupdate
drwxr-xr-x.  2 ntp            ntp               6 Jun 23  2020 ntp
drwx------.  2 root           root              6 Apr  1  2020 udisks2
drwx------.  2 setroubleshoot setroubleshoot   71 Apr  1  2020 setroubleshoot
drwx------.  2 postfix        root             25 Apr  1  2020 postfix
drwxr-xr-x.  2 root           root              6 Apr  1  2020 selinux
drwxr-xr-x.  4 colord         colord           67 Apr  1  2020 colord
drwxr-xr-x.  4 root           root             32 Apr  1  2020 AccountsService
drwxr-xr-x.  2 root           root              6 Aug  9  2019 lldpad
drwxr-xr-x.  2 root           root              6 Aug  9  2019 alsa
drwxr-xr-x.  2 root           root              6 Aug  9  2019 boltd
drwxr-xr-x.  2 root           root             37 Nov 12  2018 misc
drwxr-xr-x.  3 root           root             20 Nov 12  2018 vmware
drwx------.  3 root           root             18 Nov 12  2018 authconfig
drwxr-x---.  3 root           polkitd          28 Nov 12  2018 polkit-1
drwx------.  2 root           root              6 Nov 12  2018 machines
drwxr-xr-x.  3 root           root             17 Nov 12  2018 color
drwxr-xr-x.  2 root           root              6 Oct 31  2018 fprint
drwx------.  2 rpc            rpc               6 Oct 31  2018 rpcbind
drwxr-xr-x.  2 root           root              6 Oct 31  2018 hyperv
drwxr-xr-x.  2 root           root              6 Oct 31  2018 upower
drwxr-xr-x.  2 geoclue        geoclue           6 Oct 31  2018 geoclue
drwxr-xr-x.  2 root           root              6 Apr 11  2018 games
drwx------.  2 tss            tss               6 Aug  4  2017 tpm
drwxr-xr-x.  2 root           root              6 Nov  6  2016 os-prober
[root@harbor harbor]#


[root@harbor harbor]# systemctl start docker
[root@harbor harbor]#

[root@harbor harbor]# cd /opt/harbor
[root@harbor harbor]# docker-compose up -d

[root@harbor harbor]# docker ps
CONTAINER ID   IMAGE                                  COMMAND                  CREATED          STATUS                    PORTS                                                                                                                       NAMES
4a5bfa81b45c   goharbor/harbor-jobservice:v2.5.3      "/harbor/entrypoint.…"   36 seconds ago   Up 30 seconds (healthy)                                                                                                                               harbor-jobservice
84e56c73d4f3   goharbor/nginx-photon:v2.5.3           "nginx -g 'daemon of…"   36 seconds ago   Up 30 seconds (healthy)   0.0.0.0:4443->4443/tcp, :::4443->4443/tcp, 0.0.0.0:80->8080/tcp, :::80->8080/tcp, 0.0.0.0:443->8443/tcp, :::443->8443/tcp   nginx
428c9c084a5e   goharbor/notary-server-photon:v2.5.3   "/bin/sh -c 'migrate…"   36 seconds ago   Up 30 seconds                                                                                                                                         notary-server
bd109ef2b39d   goharbor/trivy-adapter-photon:v2.5.3   "/home/scanner/entry…"   36 seconds ago   Up 32 seconds (healthy)                                                                                                                               trivy-adapter
c6c85300ef0c   goharbor/harbor-core:v2.5.3            "/harbor/entrypoint.…"   36 seconds ago   Up 31 seconds (healthy)                                                                                                                               harbor-core
cf853691efe7   goharbor/notary-signer-photon:v2.5.3   "/bin/sh -c 'migrate…"   36 seconds ago   Up 31 seconds                                                                                                                                         notary-signer
44890b72a4b1   goharbor/harbor-db:v2.5.3              "/docker-entrypoint.…"   56 seconds ago   Up 33 seconds (healthy)                                                                                                                               harbor-db
8868cac0ecdb   goharbor/chartmuseum-photon:v2.5.3     "./docker-entrypoint…"   56 seconds ago   Up 33 seconds (healthy)                                                                                                                               chartmuseum
635cdbac8857   goharbor/redis-photon:v2.5.3           "redis-server /etc/r…"   56 seconds ago   Up 33 seconds (healthy)                                                                                                                               redis
79a641229798   goharbor/harbor-portal:v2.5.3          "nginx -g 'daemon of…"   56 seconds ago   Up 33 seconds (healthy)                                                                                                                               harbor-portal
3ea1ce798228   goharbor/registry-photon:v2.5.3        "/home/harbor/entryp…"   56 seconds ago   Up 33 seconds (healthy)                                                                                                                               registry
2d063a15136b   goharbor/harbor-registryctl:v2.5.3     "/home/harbor/start.…"   56 seconds ago   Up 33 seconds (healthy)                                                                                                                               registryctl
38649bae22f6   goharbor/harbor-log:v2.5.3             "/bin/sh -c /usr/loc…"   56 seconds ago   Up 35 seconds (healthy)   127.0.0.1:1514->10514/tcp                                                                                                   harbor-log
[root@harbor harbor]#

最终的效果,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[root@harbor harbor]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 7.8G     0  7.8G   0% /dev
tmpfs                    7.8G     0  7.8G   0% /dev/shm
tmpfs                    7.8G  3.1M  7.8G   1% /run
tmpfs                    7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/mapper/centos-root  100G   12G   89G  12% /
/dev/mapper/centos-home   47G   39M   47G   1% /home
/dev/sdb1                296G  1.8G  279G   1% /data
/dev/sda1               1014M  180M  835M  18% /boot
tmpfs                    1.6G   12K  1.6G   1% /run/user/42
tmpfs                    1.6G     0  1.6G   0% /run/user/0
overlay                  296G  1.8G  279G   1% /data/docker/overlay2/1c5bc9f64b7e787dd55b5078d1b4d04fa3a0a3cd972170316858e2e009e66c70/merged
overlay                  296G  1.8G  279G   1% /data/docker/overlay2/c0cf89b59b8e9a75e891ce8ef19984a2bc2e94d27a178064bb677dc6b8d6a87f/merged
overlay                  296G  1.8G  279G   1% /data/docker/overlay2/b94652b7ac753a378b24ff17a2224c35eaff0afc9033266857b35df7112dbde7/merged
overlay                  296G  1.8G  279G   1% /data/docker/overlay2/838ccae83474c7c2beb590c830f0d60967a77c46bd2c2485ef703c751220abce/merged
overlay                  296G  1.8G  279G   1% /data/docker/overlay2/0b9900414fe8f919e0c1d072edfeab983799054f3792dcc13d321ae19c742472/merged
overlay                  296G  1.8G  279G   1% /data/docker/overlay2/80168eae76ded9c53f4b4fb4ac90938d91667af0bc24091ab63f4e5c767ac2e3/merged
overlay                  296G  1.8G  279G   1% /data/docker/overlay2/475928e78d693f8dfcac1b69814cd495bf74d418161d5c692be456e63b1287ed/merged
overlay                  296G  1.8G  279G   1% /data/docker/overlay2/c7207ae10de6ad860607af706b4cbfa16bc7552f595f98f157ac4352c2821316/merged
overlay                  296G  1.8G  279G   1% /data/docker/overlay2/5008d4cc4aece20c24ae78ceff089957c377d3b323ca31a97268e6d1406aabe8/merged
overlay                  296G  1.8G  279G   1% /data/docker/overlay2/65b60521418f7a97e47a12599720683e5e7579dd7e9146f85368fa20c2434700/merged
overlay                  296G  1.8G  279G   1% /data/docker/overlay2/8ffbb85a07c031e2df5c22017e58523986a03a861f2a4fbbda111b2abcadf5d3/merged
overlay                  296G  1.8G  279G   1% /data/docker/overlay2/0f73f670f80c4231955ba40e48db62087f16f5244fa2067adf0403583fda5afa/merged
overlay                  296G  1.8G  279G   1% /data/docker/overlay2/92ea5fbaaa9b2c3a895805e287980bf58172c85d7f11d3dc6e22fa1d15ab6ccf/merged
[root@harbor harbor]#

overlay绑定到了/data/下容量大的磁盘上

This post is licensed under CC BY 4.0 by the author.