docker容器迁移

安装go

sudo apt update
sudo apt install golang-go

安装docker-backup

git clone https://github.com/muesli/docker-backup.git
cd docker-backup
go build

编辑.bashrc, 添加下面变量

alias docker-backup='/root/docker-backup/docker-backup'

刷新

source .bashrc

查看要备份的容器id

docker ps

备份一个容器

<container ID>可以换成<container NAME>
mkdir docker
cd docker
docker-backup backup --tar <container ID>

运行完成会得到一个.tar文件, sftp等工具迁移到新的vps, 在新的vps上同样要安装docker-backup, 然后执行这个命令

docker-backup restore --start <backup file>

如果提示没有对应镜像, docker pull后重新恢复就好了

docker-backup的详细用法见文档

GitHub - muesli/docker-backup: A tool to create & restore complete, self-contained backups of Docker containers
A tool to create & restore complete, self-contained backups of Docker containers - muesli/docker-backup