Containers won't restart after host reboot

Hello,

I have a Raspberry Pi 4 running Raspberry Pi OS 64-bit.

OS: Debian GNU/Linux 11 (bullseye) aarch64
Host: Raspberry Pi 4 Model B Rev 1.2
Kernel: 6.1.21-v8+

I have a docker project using docker compose. I have set the restart policy to always in my docker-compose.yml. However, when I reboot the Pi using reboot now or mimic a reboot using systemctl restart docker or service docker restart the containers don’t restart.

docker version

Client: Docker Engine - Community
 Version:           24.0.5
 API version:       1.43
 Go version:        go1.20.6
 Git commit:        ced0996
 Built:             Fri Jul 21 20:35:38 2023
 OS/Arch:           linux/arm64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          24.0.5
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.6
  Git commit:       a61e2b4
  Built:            Fri Jul 21 20:35:38 2023
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.6.22
  GitCommit:        8165feabfdfe38c65b599c4993d227328c231fca
 runc:
  Version:          1.1.8
  GitCommit:        v1.1.8-0-g82f18fe
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

docker compose version
Docker Compose version v2.20.2

Part of my docker-compose.yml :

version: "3.8"

x-bb-common: &common
  networks:
    - internal
  restart: always
  deploy:
    resources:
      limits:
        cpus: "3"
        memory: 3072M
    restart_policy:
      max_attempts: 3

networks:
  internal:
    external: false
    driver: bridge

services:
  caddy:
    container_name: caddy
    image: caddy:2.6-alpine
    ports:
      - "80:80"
      - "443:443"
      - "443:443/udp"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
      - ./site:/srv
      - ./data:/data
      - ./config:/config
    extra_hosts:
      - host.docker.internal:host-gateway
    <<: *common

I have already tried re-installing docker. I have also made sure that docker and containerd services start after a reboot. The mimic reboot is the case when docker service restarts after boot using systemctl restart docker or service docker restart. The docker ps output is empty. Can someone please help me debug this?

Could it be, because you mix restart and deploy.restart_policy?

You might want to try if it works, if you either remove deploy.restart_policy, or configure the policy as deploy.restart_policy.condition:

x-bb-common: &common
  networks:
    - internal
  deploy:
    resources:
      limits:
        cpus: "3"
        memory: 3072M
    restart_policy:
      condition: any
      max_attempts: 3

See for further details: https://docs.docker.com/compose/compose-file/deploy/#restart_policy

Update: the answer to my question is answered in the link I shared:

restart_policy configures if and how to restart containers when they exit. If restart_policy is not set, Compose considers the restart field set by the service configuration.

2 Likes

It worked! Thank you so much.
I missed this and have been messing with my OS and docker install for 2 days. :sweat_smile: