0

I want to be able to "freeze" a container state into a file and then restore it later if the container is accidentally deleted. This is to prevent accidental container deletion.

I tried docker export to a tar file, then docker import, but it will create an image of the docker filesystem... not the container itself. I know that I can use docker run from this image but I am not the container creator and I don't know what command was used to create it originally.

I also tried to use docker-runc to recreate the container from its rootfs and config.json from /run/docker/libcontainerd/CONTAINER_ID/config.json, but I see that this will not be easy and I wanted a "not so hack-ish" solution.

Currently, the only way I know to achieve this is to create snapshots of the docker host VM and, if someone accidentally deletes a container, restore the snapshot. But the last time this happened, the last backup was taken 16 hours before, and I lost all data created after that (and the recovery process too a good amount of time).

I just wanted to save the container state into a file and be able to recreate it in case of deletion.

ThiagoAlves
  • 1,313
  • 16
  • 25

1 Answers1

1

You can use docker autocompose to get a docker-compose.yml equivalent that will allow you to recreate the container together with the image you saved.

fernandezcuesta
  • 2,390
  • 1
  • 15
  • 32
  • Yes, this would solve my problem. Unfortunately I got an error for the docker-compose file generated by the tool: `# docker-compose -f /tmp/backup_c1 up -d Creating c1 ... Creating c1 ... error ERROR: for c1 Cannot start service c1: b'oci runtime error: container_linux.go:262: starting container process caused "exec: \\"nginx -g daemon off;\\": executable file not found in $PATH"'` – ThiagoAlves Aug 29 '17 at 12:10
  • That might be related to incompatibilities between the file generated (file version 1) and the docker engine/compose. What about just doing a `docker commit`? That should keep environment variables, exposed ports, etc. – fernandezcuesta Aug 29 '17 at 12:50
  • `docker commit` will also create an image - not a container – ThiagoAlves Aug 29 '17 at 13:26
  • I have found the error on docker-autocompose and will send a PR to fix it. – ThiagoAlves Aug 29 '17 at 13:27