如何将卷数据从docker for mac迁移到colima



如何将卷从docker-for-mac移动到colima

将从docker-for-mac复制所有卷并将其移动到colima

注意:会有很多卷您可能不想复制,因为它们是临时卷,您可以通过在awk之前或之后向for循环添加| grep "YOUR FILTER"来忽略它们

以下代码做了两个假设:

  1. 您已经安装并运行了docker for mac
  2. 你在跑步

这就是您所需要的,现在将其复制并粘贴到您的终端中。不需要触摸任何东西。

(
# set -x  # uncomment to debug
set -e
# ssh doesn't like file descriptor piping, we need to write the configuration into someplace real
tmpconfig=$(mktemp);
# Need to have permissions to copy the volumes, and need to remove the ControlPath and add ForwardAgent
(limactl show-ssh --format config colima | grep -v "^  ControlPath|  ^User"; echo "  ForwardAgent=yes") > $tmpconfig;
# Setup root account
ssh -F $tmpconfig $USER@lima-colima "sudo mkdir -p /root/.ssh/; sudo cp ~/.ssh/authorized_keys /root/.ssh/authorized_keys"
# Loop over each volume inside docker-for-mac
for volume_name in $(DOCKER_CONTEXT=desktop-linux docker volume ls | awk '{print $2}'); do 
echo $volume_name;
# Make the volume backup
DOCKER_CONTEXT=desktop-linux docker run -d --rm --mount source=$volume_name,target=/volume --name copy-instance busybox sleep infinate; 
DOCKER_CONTEXT=desktop-linux docker exec copy-instance sh -c "tar czf /$volume_name.tar /volume";
DOCKER_CONTEXT=desktop-linux docker cp copy-instance:/$volume_name.tar /tmp/$volume_name.tar; 
DOCKER_CONTEXT=desktop-linux docker kill copy-instance;
# Restore the backup inside colima
DOCKER_CONTEXT=colima docker volume create $volume_name;
ssh -F $tmpconfig root@lima-colima "rm -rf /var/lib/docker/volumes/$volume_name; mkdir -p /var/lib/docker/volumes/$volume_name/_data";
scp -r -F $tmpconfig /tmp/$volume_name.tar root@lima-colima:/tmp/$volume_name.tar;
ssh -F $tmpconfig root@lima-colima "tar -xf /tmp/$volume_name.tar --strip-components=1 --directory /var/lib/docker/volumes/$volume_name/_data";

done
)

相关内容

  • 没有找到相关文章

最新更新