How does Docker-Compose/Deamon know which container to boot after a reboot?

293 Views Asked by At

I am asking from a purely technological point of view - I am aware that I can specify a restart policy in Docker Compose. But I wonder where the information to this question "Which containers were running when the reboot/power failure occurred ?" is stored. Or asked the other way, how does the Deamon know which container to boot after the reboot?

And is there any possibility to edit this "file"/"information"?

1

There are 1 best solutions below

1
On BEST ANSWER

The Docker daemon keeps internal state to know which containers are running, what image they were started from, and startup-time settings like their command and port mappings. You can't directly see or access this data.

For most container settings, the most robust way to change them is to stop, delete, and recreate the container. This is very routine, and you should make sure to configure the container so that you don't lose any data when you delete it. (Store data outside the container, for example in a database, if at all possible, and if not, use a volume mount to store data.)

A limited number of things can be updated with docker update without restarting the container, that happens to include the restart policy. If you're using Compose, you can update the restart: setting in the docker-compose.yml file and re-run docker-compose up -d, which will apply the updated setting (probably by deleting and recreating the container).