我是 docker 和容器的新手。 我按照以下步骤迁移在 docker 容器上运行的 postgres 数据库:
docker save -o <path for generated tar file> <image name>
scp <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a4d6cbcbd0e4959d968a95948a958a91" rel="noreferrer noopener nofollow">[email protected]</a>:/images/gpdb.tar <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cab8a5a5be8afbf3f8e4fbfae4f8e4ff" rel="noreferrer noopener nofollow">[email protected]</a>:/images
在目标服务器(192.10.2.5)中:
docker load -i /images/gpdb.tar
但是,当我登录到 docker 镜像时,数据库不存在。 如何保存包含所有数据库表和数据的 docker 镜像。
最佳答案
没有数据库,因为 docker save
和 docker 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
关于docker - 保存docker镜像的当前状态并导出到另一台服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53275779/