我是docker和container的新手。我按照以下步骤迁移了在Docker容器上运行的postgres数据库:
docker save -o <path for generated tar file> <image name>
scp [email protected]:/images/gpdb.tar [email protected]:/images
在目标服务器(192.10.2.5)中:
docker load -i /images/gpdb.tar
但是,当我登录到docker映像时,数据库不存在。如何将docker映像与所有数据库表和数据一起保存。
没有数据库,因为docker save
anddocker commit
命令不会保存容器卷...
这是执行此操作的脚本:
https://github.com/ricardobranco777/docker-volumes.sh
# Stop the container
docker stop $CONTAINER
# Create a new image
docker commit $CONTAINER $CONTAINER
# Save and load image to another host
docker save $CONTAINER | ssh $USER@$HOST docker load
# Save the volumes (use ".tar.gz" if you want compression)
docker-volumes.sh $CONTAINER save $CONTAINER-volumes.tar
# Copy image and volumes to another host
scp $CONTAINER.tar $CONTAINER-volumes.tar $USER@$HOST:
### On the other host:
# Create container with the same options used by the previous container
docker create --name $CONTAINER [<PREVIOUS CONTAINER OPTIONS>] $CONTAINER
# Load the volumes
docker-volumes.sh $CONTAINER load $CONTAINER-volumes.tar
# Start container
docker start $CONTAINER
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句