Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker-compose is starting containers after host reboot. Which ones?

I'm new to docker-compose. Before, when I started containers manually, after a host reboot I had to start the containers manually.

Today I found that -after a host reboot- I had 4 containers running. Those were previously started with docker-compose.

But docker-compose does not work well unless you are in the proper directory with the docker-compose.yml.

Question

How can I know what docker-compose.yml or (which path) was used to launch the docker containers that I find already started as soon as I login after a reboot?

I tried

docker inspect xxxxx

but I could not find any clue on what docker-compose.yml was used to launch.

like image 504
Xavi Montero Avatar asked Aug 14 '19 23:08

Xavi Montero


People also ask

What happens to docker containers on reboot?

Docker provides restart policies to control whether your containers start automatically when they exit, or when Docker restarts. Restart policies ensure that linked containers are started in the correct order. Docker recommends that you use restart policies, and avoid using process managers to start containers.

Does Docker compose restart on reboot?

Like the restart Docker command, Docker Compose includes the restart property to restart containers automatically.

Does Docker compose restart containers?

You need to stop it and start again. Or, using single command docker-compose up will detect changes and recreate container. As many others mentioned, if you changed docker-compose. yml file itself, simple restart won't apply those changes.

How do I make docker start automatically after reboot?

If you're using a recent Ubuntu (e.g., 20) and you installed docker via apt , all you have to do is sudo systemctl enable --now docker . That will enable the docker service in systemd and start it right then if it hasn't already started.


1 Answers

docker-compose is not starting anything.

The Docker daemon is starting containers on which you have set a restart policy (possibly in one of your docker-compose.yaml files). You can simply remove these containers (docker container rm ...) if you don't need them anymore, or you can reset the restart policy using docker container update --restart=no <image_name_or_id>.

You can read more about restart policies here.

But docker-compose does not work well unless you are in the proper directory with the docker-compose.yml.

Since docker-compose isn't involve at this stage (it may have been responsible for creating the containers but it is not responsible for restarting them), this isn't a problem. Setting an appropriate restart policy on your containers via your docker-compose.yml is the correct way to enable containers to start at boot.


You can set a restart policy when you start a container using docker run by including the appropriate --restart=<policy> option on the command line.

like image 109
larsks Avatar answered Oct 30 '22 19:10

larsks