C. Hediger
C. Hediger

Reputation: 482

Docker backup container with startup parameters

Im facing the same problem since months now and i dont have an adequate solution.

Im running several Containers based on different images. Some of them were started using portainer with some arguments and volumes. Some of them were started using the CLI and docker start with some arguments and parameters.

Now all these settings are stored somewhere. Because if i stop and retart such a container, everything works well again. but, if i do a commit, backup it with tar and load it on a different system and do a docker start, it has lost all of its settings.

The procedure as described here: https://linuxconfig.org/docker-container-backup-and-recovery does not work in my case.

Now im thinking about to write an own web application which will create me some docker compose files based on my setting rather than to just do a docker start with the correct params. This web application should also take care of the volumes (just folders) and do a incremental backup of them with borg to a remote server.

But actually this is only an idea. Is there a way to "extract" a docker compose file of a running containter? So that i can redeploy a container 1:1 to an other server and just have to run docker run mycontainer and it will have the same settings?

Or do i have to write my web app? Or have i missed some page on google and there is already such a solution?

Thank you!

Upvotes: 3

Views: 4875

Answers (2)

BMitch
BMitch

Reputation: 264791

To see the current configuration of a container, you can use:

docker container inspect $container_id

You can then use those configurations to run your container on another machine. There is no easy import/export of these settings to start another container that I'm aware of.

Most people use a docker-compose.yml to define how they want a container run. They also build images with a Dockerfile and transfer them with a registry server rather than a save/load.

The docker-compose.yml can be used with docker-compose or docker stack deploy and allows the configuration of the container to be documented as a configuration file that is tracked in version control, rather than error prone user entered settings. Running containers by hand or starting them with a GUI is useful for a quick test or debugging, but not for reproducibility.

Upvotes: 3

Stefano
Stefano

Reputation: 5076

You would like to backup the instance but the commands you're providing are to backup the image. I'd suggest to update your Dockerfile to solve the issue. In case you really want to go down the saving the instance current status, you should use the docker export and docker import commands.

Reference:

https://docs.docker.com/engine/reference/commandline/import/ https://docs.docker.com/engine/reference/commandline/export/


NOTE: the docker export does not export the content of the volumes anyway, I suggest you to should refer to https://docs.docker.com/engine/admin/volumes/volumes/

Upvotes: 0

Related Questions