Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Containers not restarted after update with restart always in docker-compose.yml

I have some containers which all of them have the always restart value in the docker-compose file like this:

version: "3.7"
services:

  container:
    image: ghost:latest
    container_name: some_container
    restart: always
    depends_on:
       - ...
    ports:
       - ...
...

As soon as the OS (Flatcar Linux / CoreOS) has updated itself none of the containers restart. But if I just do $ sudo docker ps all of the containers starts at once. Whats up with that and how do I fix it so my containers automatically restarts after an update?

EDIT:

Not sure what is unclear about my question, restart: always is turned on. Unless I'm missing some vital thing in the documentation, this command should restart the container even if the docker daemon is restarted (after an os reboot).

Copy of one my comments from below:

Ok, so help me out here. As you can see in my question, I have restart: always turned on. All these containers are started successfully and are running well. Then the OS updates itself automatically and restarts itself. After this restart the docker daemon is restarted. But for some reasons the containers I had running WITH RESTART: ALWAYS turned on DOES NOT START. If I enter my server at this moment, type sudo docker ps to list my running containers, suddenly all containers are booted up and I see the list. So why wasn't the containers started, even though the daemon is running?

like image 917
just_user Avatar asked Nov 02 '20 11:11

just_user


People also ask

Does Docker compose automatically restart container?

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

Does restarting docker restart all containers?

For a major version upgrade, one has to tear down all running containers. With a restart policy of always , however, the containers will be restarted after the docker daemon is restarted after the upgrade.

What does restart always do in docker?

This prevents a container which does not start at all from going into a restart loop. If you manually stop a container, its restart policy is ignored until the Docker daemon restarts or the container is manually restarted. This is another attempt to prevent a restart loop. Restart policies only apply to containers.

Does restarting docker stop containers?

2.4. In fact, a Docker service restart will stop all Docker containers.


2 Answers

From the comments it appears the docker service was not configured to automatically start on boot. Docker is a client server app, and the server runs from systemd with a separate service for the docker socket used by the client to talk to the server. Therefore it's possible for any call with the docker command to cause the server to get launched by hitting the docker socket.

The service state in systemd can be checked with:

systemctl status docker

or you may want to check:

systemctl is-enabled docker

It can be manually started with:

systemctl start docker

And it can be enabled to start with:

systemctl enable docker

All of the above commands need to be run as root.

like image 170
BMitch Avatar answered Oct 21 '22 22:10

BMitch


This requires the Docker service to get started on boot instead of using the default socket activation that starts on-demand like you decribed with execution of "docker ps"

Here is the required Container Linux Config to enable the Docker service while disabling socket activation:

systemd:
  units:
    # Ensure docker starts automatically instead of being socket-activated
    - name: docker.socket
      enabled: false
    - name: docker.service
      enabled: true
like image 3
ppannek Avatar answered Oct 22 '22 00:10

ppannek