docker 删除默认连接_如何从已删除的Docker容器中恢复数据?如何重新连接到数据?...

Let's say, I delete a PostgreSQL docker container which had its data only here:

$ docker inspect postgres1

...

"Source": "/var/lib/docker/volumes/4948af..../_data"

"Destination": "/var/lib/postgresql/data"

$ docker rm postgres1

If there was no other container referencing the volume, I cannot reconnect to this volume with --volumes-from any more, even though the files are still on disk somewhere in: /var/lib/docker/volumes/...

This presents me with two problems:

What is the best way to locate the data, if I do not know the volume UUID of the directory?

Doing ls /var/lib/docker/volumes/ presents me with a hundred dirs like this f77c92....

Using find . -name "*postgres*" I still get dozens of results like this ...10e0dc/_data/postgresql.conf, with no clear way to identify the right one.

Once I find the correct data in the directory, how do I reconnect a newly created postgres container to this data in /var/lib/docker/volumes/4948af.../_data

I have a daily full system rsync backup. How could this help in recovery (short of restoring the whole system)?

解决方案

That is exactly why, when creating a data container, I always register its path in a file. (see my script updateDataContainerPath)

Usage (to be used just after creating a data container):

docker inspect ${gitolite_repos_cont} > /dev/null 2>&1 || docker create --name="${gitolite_repos_cont}" gitolite.repos /bin/true

# source the script, to make the updatePath() function available

. ../updateDataContainerPath

# save the path in a file

updatePath ${gitolite_repos_cont} "$HOME/b2d/gitolite" ${grepos}

(here ${grepos} is the file where you register or save the path of the volume of the data container)

That script will, if there was already a path saved for that data container, remove the empty data container folder, and move the old one to the new one (and update the new path)

sudo rm -Rf "${grpath}"

sudo mv "${fgrpath}" "${grpath}"

That would help answering your question 2, and avoid entirely your question 1.

That way, I can rm any container (including a data container, without the -v option of course), and I know the next time I recreate that same data container, I will find back my data.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值