menu Chancel's blog
rss_feed
Chancel's blog
秋雨一何碧,山色倚晴空。

Docker备份容器

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

备份步骤

  1. commit container
  2. save container to tar file

恢复步骤

  1. load container by tar file

全部步骤指令

# 打印当前所有容器
❯ 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
类型:Virtualization
创建时间:2021 Jun 16
更新时间:2022 May 26

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

account_circle
email
web_asset
textsms

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

还没有可以显示的留言...
[[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)]]