Docker containers are being restarted after logging in via SSH

  • 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'
        image: pihole/pihole:latest
          - "53:53/tcp"
          - "53:53/udp"
          - "67:67/udp"
          - "9080:80/tcp"
          - "9443:443/tcp"
          TZ: 'Europe/Amsterdam'
          # WEBPASSWORD: 'set a secure password here or it will be random'
        # Volumes store your data between container upgrades
           - './etc-pihole/:/etc/pihole/'
           - './etc-dnsmasq.d/:/etc/dnsmasq.d/'
        # Recommended but not required (DHCP needs NET_ADMIN)
          - 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            >1900/udp, :::1900->1900/udp,>5514/tcp, :::5514->5514/tcp,>6789/tcp, :::6789->6789/tcp,>8080/tcp, :::8080->8080/tcp,>8443/tcp, :::8443->8443/tcp,>8843/tcp, :::8843->8843/tcp,>3478/udp, :::3478->3478/udp,>10001/udp, :::10001->10001/udp,>8880/tcp, :::8880->8880/tcp   unifi-controller-unifi-controller-1
    b6b1733befc6   pihole/pihole:latest           "/s6-init"               25 minutes ago   Up 3 seconds (health: starting)>53/udp, :::53->53/udp,>53/tcp,>67/udp, :::53->53/tcp, :::67->67/udp,>80/tcp, :::9080->80/tcp,>443/tcp, :::9443->443/tcp                                                                                                                                                                                                                 pihole-pihole-1
    47c751c5912b   nginx                          "/docker-entrypoint.…"   30 minutes ago   Up 3 seconds            >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
       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 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?

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

    I had to enable lingering:

    $ loginctl enable-linger $UID

Log in to reply

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2