What is the easiest way to backup docker compose?

i want to back up server which is the easy way to backup or sync it ??

May I suggest to be more specific about what exactl you want to backup or sync?

1 Like

i want to backup whole docker or docker compose file
like what if i want keep container that i install
then i want to install new os & i restore it.

or automatic sync docker to cloud.

“Whole docker” == the whole docker engine installation from /var/lib/docker?
“Whole docker” == the whole conantainer including the image and all volumes?

I doubt that backing up /var/lib/docker and restoring it will succeed as overlay2 will present a virtual filesystem for each image/container, which might be interpreted as physical files. Never tried it though, as I don’t trust this approach. If you compare sudo du --human-readable --max-depth=1 --one-file-system /var/lib/docker and sudo docker system df, both should show the same size. But if you ue the command sudo du --human-readable --max-depth=1 /var/lib/docker will show a different result, as files are counted multiple times - I would expect a backup to backup files multiple times and “break” the overlay2 “magic” when it restores the files.

Personaly, I would solve it in a different way:

  • instead of backing up images:
    • run a private container registry
    • use the registry to pull through the images
  • instead of backing up docker-compose file:
    • keep the docker-compose.yml and all files required by it in git
  • instead of backing up a while container
    • backup all volumes of containers (for the sake of consistency with stopped container)
    • sync the backups to a target environment

Update: I realized I missed the most imortant part “what is the easiest way”. I hav no idea what the easiest way is. I just know how to backup the relevant parts in a consistent way - but I am afraid it fails on the requirement of beeing easy.

2 Likes

please advice the image and all volume method.

@meyay just did that. Read his list of recommendations again. Do you have a more specific question?

1 Like

do i need to git clone before use git add .