menu E4b9a6's blog
rss_feed
E4b9a6's blog
有善始者实繁,能克终者盖寡。

Docker备份容器

作者:E4b9a6, 创建:2021-06-16, 字数:1345, 已阅:77, 最后更新:2024-03-10

这篇文章更新于 258 天前,文中部分信息可能失效,请自行甄别无效内容。

在NAS上运行的Docker容器PhotoPrism需要备份以防万一(当然备份原始照片数据更重要)

备份步骤

  1. commit container
  2. save container to tar file

恢复步骤

  1. load container by tar file

全部步骤指令

Bash
# 打印当前所有容器
❯ docker ps
CONTAINER ID   IMAGE                          COMMAND                  CREATED       STATUS       PORTS                     NAMES
a48bc98b4a21   photoprism/photoprism:latest   "/entrypoint.sh phot…"   2 weeks ago   Up 5 hours   0.0.0.0:32342->2342/tcp   chancel_photoprism_1
f1d7d5ac091f   mariadb:10.5                   "docker-entrypoint.s…"   2 weeks ago   Up 5 hours   3306/tcp                  chancel_mariadb_1

# 提交需要备份的容器
❯ docker commit -p a48bc98b4a21 photoprism-container-backup

# 查看镜像列表
❯ docker images
REPOSITORY                    TAG       IMAGE ID       CREATED         SIZE
photoprism-container-backup   latest    cc71161fb644   4 minutes ago   14.3GB
hello-world                   latest    d1165f221234   2 weeks ago     13.3kB
mariadb                       10.5      e27cf5bc24fe   2 weeks ago     401MB
photoprism/photoprism         latest    f81f7b1e47a4   3 weeks ago     1.3GB

# 导出已保存的镜像备份为tar压缩文件
❯ docker save -o ~/photoprism-container-backup.tar photoprism-container-backup

# 导入已保存的镜像备份tar文件
❯ docker load -i ~/photoprism-container-backup.tar

# 重新使用镜像运行容器
docker run -d -p 32342:2342 container-backup photoprism-container-backup

[[replyMessage== null?"发表评论":"发表评论 @ " + replyMessage.m_author]]

account_circle
email
web_asset
textsms

评论列表([[messageResponse.total]])

还没有可以显示的留言...
gravatar
[[messageItem.m_author]] [[messageItem.m_author]]
[[messageItem.create_time]]
[[getEnviron(messageItem.m_environ)]]
[[subMessage.m_author]] [[subMessage.m_author]] @ [[subMessage.parent_message.m_author]] [[subMessage.parent_message.m_author]]
[[subMessage.create_time]]
[[getEnviron(messageItem.m_environ)]]