Mlgarate
Mlgarate

Reputation: 11

copy container Docker using ssh

We have some docker containers in a dedicated Server. Something happened and now the drive is readonly. we cannont remount it as read write. fsck return WARNING filesystem still has errors.

Hetzner offers us to buy a new drive, but it will be empty and we need to copy all the data in docker to the new disk.

each container has a postgres db. we can access using ssh. Any idea on how to do it?

Upvotes: 0

Views: 44

Answers (1)

larsks
larsks

Reputation: 312273

You can use docker export to export a container as a tar file (and docker import to import it on another system). However, data like your postgres database is generally stored in docker volumes and won't be part of the export/import process.

For postgres in particular, you would want to perform a database backup using pg_dump.

More generally, you can back up volumes by running tar inside a container to export the data, as in:

docker exec <oldcontainer> tar -C /my/data -cf- > data.tar

The process for importing the data somewhere else will be similar:

docker exec -i <newcontainer> -tar -C /my/data -xf- < data.tar

Even more generally, you should arrange for automatic backups of your important data. It's possible that you will not be able to extract all your data due to the problems with your disks.

Upvotes: 1

Related Questions