最近想把一台服务器(服务器A,接入互联网)的docker里跑的一个服务原样迁移到另外一台服务器(服务器B,无互联网连接)的docker里,两台服务器的系统版本、docker版本、docker compose版本都是完全一样的,可以说是两台条件完全相同的服务器。
使用docker ps -a
命令得到如下回复(这么多容器之间互相是依赖和被依赖的关系):
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f0f2fa2783bf ghcr.io/anyproto/any-sync-tools:latest "tail -f /dev/null" 2 days ago Exited (255) 44 seconds ago 443/tcp, 8000/tcp, 8080/tcp any-sync-dockercompose-main-netcheck-1
c2d7baa8dc98 ghcr.io/anyproto/any-sync-consensusnode:v0.2.0 "/bin/any-sync-conse…" 2 days ago Exited (255) 44 seconds ago 443/tcp, 8080/tcp, 0.0.0.0:1006->1006/tcp, :::1006->1006/tcp, 0.0.0.0:1016->1016/udp, :::1016->1016/udp, 0.0.0.0:8006->8000/tcp, :::8006->8000/tcp any-sync-dockercompose-main-any-sync-consensusnode-1
be211624c0e6 ghcr.io/anyproto/any-sync-filenode:v0.8.1 "/bin/any-sync-filen…" 2 days ago Exited (255) 44 seconds ago 443/tcp, 8080/tcp, 0.0.0.0:1005->1005/tcp, :::1005->1005/tcp, 0.0.0.0:1015->1015/udp, :::1015->1015/udp, 0.0.0.0:8004->8000/tcp, :::8004->8000/tcp any-sync-dockercompose-main-any-sync-filenode-1
5672983d8e41 ghcr.io/anyproto/any-sync-node:v0.4.7 "/bin/any-sync-node …" 2 days ago Exited (255) 44 seconds ago 443/tcp, 0.0.0.0:1003->1003/tcp, :::1003->1003/tcp, 0.0.0.0:1013->1013/udp, :::1013->1013/udp, 0.0.0.0:8003->8000/tcp, :::8003->8000/tcp, 0.0.0.0:8083->8080/tcp, :::8083->8080/tcp any-sync-dockercompose-main-any-sync-node-3-1
553a3dcacf7f ghcr.io/anyproto/any-sync-node:v0.4.7 "/bin/any-sync-node …" 2 days ago Exited (255) 44 seconds ago 443/tcp, 0.0.0.0:1002->1002/tcp, :::1002->1002/tcp, 0.0.0.0:1012->1012/udp, :::1012->1012/udp, 0.0.0.0:8002->8000/tcp, :::8002->8000/tcp, 0.0.0.0:8082->8080/tcp, :::8082->8080/tcp any-sync-dockercompose-main-any-sync-node-2-1
2f3f0c82f277 ghcr.io/anyproto/any-sync-node:v0.4.7 "/bin/any-sync-node …" 2 days ago Exited (255) 44 seconds ago 443/tcp, 0.0.0.0:1001->1001/tcp, :::1001->1001/tcp, 0.0.0.0:1011->1011/udp, :::1011->1011/udp, 0.0.0.0:8001->8000/tcp, :::8001->8000/tcp, 0.0.0.0:8081->8080/tcp, :::8081->8080/tcp any-sync-dockercompose-main-any-sync-node-1-1
36d83a604787 ghcr.io/anyproto/any-sync-coordinator:v0.4.2 "/bin/any-sync-coord…" 2 days ago Exited (255) 44 seconds ago 443/tcp, 8080/tcp, 0.0.0.0:1004->1004/tcp, :::1004->1004/tcp, 0.0.0.0:1014->1014/udp, :::1014->1014/udp, 0.0.0.0:8005->8000/tcp, :::8005->8000/tcp any-sync-dockercompose-main-any-sync-coordinator-1
95dc521aabba ghcr.io/anyproto/any-sync-coordinator:v0.4.2 "/bin/any-sync-confa…" 2 days ago Exited (0) 2 days ago any-sync-dockercompose-main-any-sync-coordinator_bootstrap-1
2a2a2d984d43 mongo:7.0.2 "docker-entrypoint.s…" 2 days ago Exited (255) 44 seconds ago 27017/tcp any-sync-dockercompose-main-mongo-1-1
41bab00db3d1 redis/redis-stack-server:7.2.0-v6 "redis-server --port…" 2 days ago Exited (255) 44 seconds ago 6379/tcp any-sync-dockercompose-main-redis-1
98be9e66a907 minio/mc:latest "/bin/sh -c ' until …" 2 days ago Exited (0) 2 days ago any-sync-dockercompose-main-create-bucket-1
aab13fab73f8 any-sync-dockercompose-main-generateconfig-processing "bash /code/docker-g…" 2 days ago Exited (0) 2 days ago any-sync-dockercompose-main-generateconfig-processing-1
4036e480ae67 minio/minio:RELEASE.2024-07-04T14-25-45Z "/usr/bin/docker-ent…" 2 days ago Exited (255) 44 seconds ago 9000/tcp any-sync-dockercompose-main-minio-1
4f7bf3b5b0ed any-sync-dockercompose-main-generateconfig-anyconf "bash /code/docker-g…" 2 days ago Exited (0) 2 days ago any-sync-dockercompose-main-generateconfig-anyconf-1
我遇到的困难在于有几个容器是用了同一个镜像不同参数启动运行的:ghcr.io/anyproto/any-sync-node:v0.4.7
ghcr.io/anyproto/any-sync-coordinator:v0.4.2
,这种情况貌似无法使用docker save
命令实现从服务器A打包然后拿到服务器B展开即可用。
我的想法是用docker save
命令把所有的镜像都打一个包,然后再用docker export
命令把每一个容器的快照都保存下来,然后把打包好的镜像和快照文件全部拿到服务器B部署,这种方法是否可行?还有没有更稳妥或简单的方法?
11月7日增加内容:迁移可以不考虑用户数据,只考虑服务本身,保证迁移后服务可正常运行即可。