0

Docker is installed on my Raspberry Pi with Raspberry OS and running it in rootless mode. I currently have 3 docker containers running on it. The containers are running with docker compose.

The problem is that after I login via SSH, all containers restart. This is also noticeable because the login is taking like 5-10 seconds until the prompt is visible.

What is also odd is that this does not happen consequently. I can reproduce it if there is like 10 seconds in between login attempts.

What I also notice is that when I exit the terminal with CTRL + D, all docker containers stop. They start again after logging in via SSH on the PI.

Docker version: Docker-ce: 5:20.10.21~3-0~debian-bullseye

All applications have a similar docker-compose file. One example is below:

version: '3'
services:
  pihole:
    image: pihole/pihole:latest
    ports:
      - "53:53/tcp"
      - "53:53/udp"
      - "67:67/udp"
      - "9080:80/tcp"
      - "9443:443/tcp"
    environment:
      TZ: 'Europe/Amsterdam'
      # WEBPASSWORD: 'set a secure password here or it will be random'
    # Volumes store your data between container upgrades
    volumes:
       - './etc-pihole/:/etc/pihole/'
       - './etc-dnsmasq.d/:/etc/dnsmasq.d/'
    dns:
      - 127.0.0.1
      - 1.1.1.1
    # Recommended but not required (DHCP needs NET_ADMIN)
    #   https://github.com/pi-hole/docker-pi-hole#note-on-capabilities
    cap_add:
      - NET_ADMIN
    restart: on-failure:3

After logging in:

pi@raspberrypi:~ $ docker ps
CONTAINER ID   IMAGE                          COMMAND                  CREATED          STATUS                            PORTS                                                                                                                                                                                                                                                                                                                                                                                                   NAMES
bd2350eaea48   linuxserver/unifi-controller   "/init"                  25 minutes ago   Up 3 seconds                      0.0.0.0:1900->1900/udp, :::1900->1900/udp, 0.0.0.0:5514->5514/tcp, :::5514->5514/tcp, 0.0.0.0:6789->6789/tcp, :::6789->6789/tcp, 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp, 0.0.0.0:8443->8443/tcp, :::8443->8443/tcp, 0.0.0.0:8843->8843/tcp, :::8843->8843/tcp, 0.0.0.0:3478->3478/udp, :::3478->3478/udp, 0.0.0.0:10001->10001/udp, :::10001->10001/udp, 0.0.0.0:8880->8880/tcp, :::8880->8880/tcp   unifi-controller-unifi-controller-1
b6b1733befc6   pihole/pihole:latest           "/s6-init"               25 minutes ago   Up 3 seconds (health: starting)   0.0.0.0:53->53/udp, :::53->53/udp, 0.0.0.0:53->53/tcp, 0.0.0.0:67->67/udp, :::53->53/tcp, :::67->67/udp, 0.0.0.0:9080->80/tcp, :::9080->80/tcp, 0.0.0.0:9443->443/tcp, :::9443->443/tcp                                                                                                                                                                                                                 pihole-pihole-1
47c751c5912b   nginx                          "/docker-entrypoint.…"   30 minutes ago   Up 3 seconds                      0.0.0.0:80->80/tcp, :::80->80/tcp                                                                                                                                                                                                                                                                                                                                                                       nginx-web-1
pi@raspberrypi:~ $ uptime
 20:15:56 up 1 day, 57 min,  1 user,  load average: 1.34, 1.13, 0.92
pi@raspberrypi:~ $

systemctl status docker

pi@raspberrypi:~ $ systemctl status docker
● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2022-11-18 19:18:10 GMT; 24h ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 667 (dockerd)
      Tasks: 10
        CPU: 39.118s
     CGroup: /system.slice/docker.service
             └─667 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Nov 18 19:18:07 raspberrypi dockerd[667]: time="2022-11-18T19:18:07.718884305Z" level=info msg="ClientConn switching balancer to \"pick_first\"" module=grpc
Nov 18 19:18:08 raspberrypi dockerd[667]: time="2022-11-18T19:18:08.414555267Z" level=info msg="[graphdriver] using prior storage driver: overlay2"
Nov 18 19:18:08 raspberrypi dockerd[667]: time="2022-11-18T19:18:08.443483656Z" level=warning msg="Unable to find memory controller"
Nov 18 19:18:08 raspberrypi dockerd[667]: time="2022-11-18T19:18:08.444127749Z" level=info msg="Loading containers: start."
Nov 18 19:18:09 raspberrypi dockerd[667]: time="2022-11-18T19:18:09.048346693Z" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be used to set a pre>
Nov 18 19:18:09 raspberrypi dockerd[667]: time="2022-11-18T19:18:09.263348211Z" level=info msg="Loading containers: done."
Nov 18 19:18:09 raspberrypi dockerd[667]: time="2022-11-18T19:18:09.951108267Z" level=info msg="Docker daemon" commit=3056208 graphdriver(s)=overlay2 version=20.10.21
Nov 18 19:18:09 raspberrypi dockerd[667]: time="2022-11-18T19:18:09.952013081Z" level=info msg="Daemon has completed initialization"
Nov 18 19:18:10 raspberrypi systemd[1]: Started Docker Application Container Engine.
Nov 18 19:18:10 raspberrypi dockerd[667]: time="2022-11-18T19:18:10.045252137Z" level=info msg="API listen on /run/docker.sock"

Why does this happen?

1
  • Instead of ctrl+D, could you instead just do exit to logout? Aug 17, 2023 at 13:29

1 Answer 1

0

Apparently rootless mode runs Docker only when a user session starts. After stopping the session, Docker stops too.

I had to enable lingering: https://stackoverflow.com/questions/73299883/docker-containers-terminate-on-shell-logout

$ loginctl enable-linger $UID

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.