<p>Apparently rootless mode runs Docker only when a user session starts. After stopping the session, Docker stops too.</p>
<p>I had to enable lingering: <a href="https://stackoverflow.com/questions/73299883/docker-containers-terminate-on-shell-logout">https://stackoverflow.com/questions/73299883/docker-containers-terminate-on-shell-logout</a></p>
<p><code>$ loginctl enable-linger $UID</code></p>

CC BY-SA 4.0
2022-11-19T22:18:18.423Z
2022-11-19T22:18:18.423Z
com2ghz
<p>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.</p>
<p>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.</p>
<p>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.</p>
<p>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.</p>
<p>Docker version: Docker-ce: 5:20.10.21~3-0~debian-bullseye</p>
<p>All applications have a similar docker-compose file. One example is below:</p>
<pre><code>version: '3'
services:
  pihole:
    image: pihole/pihole:latest
    ports:
      - &quot;53:53/tcp&quot;
      - &quot;53:53/udp&quot;
      - &quot;67:67/udp&quot;
      - &quot;9080:80/tcp&quot;
      - &quot;9443:443/tcp&quot;
    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

</code></pre>
<p>After logging in:</p>
<pre><code>pi@raspberrypi:~ $ docker ps
CONTAINER ID   IMAGE                          COMMAND                  CREATED          STATUS                            PORTS                                                                                                                                                                                                                                                                                                                                                                                                   NAMES
bd2350eaea48   linuxserver/unifi-controller   &quot;/init&quot;                  25 minutes ago   Up 3 seconds                      0.0.0.0:1900-&gt;1900/udp, :::1900-&gt;1900/udp, 0.0.0.0:5514-&gt;5514/tcp, :::5514-&gt;5514/tcp, 0.0.0.0:6789-&gt;6789/tcp, :::6789-&gt;6789/tcp, 0.0.0.0:8080-&gt;8080/tcp, :::8080-&gt;8080/tcp, 0.0.0.0:8443-&gt;8443/tcp, :::8443-&gt;8443/tcp, 0.0.0.0:8843-&gt;8843/tcp, :::8843-&gt;8843/tcp, 0.0.0.0:3478-&gt;3478/udp, :::3478-&gt;3478/udp, 0.0.0.0:10001-&gt;10001/udp, :::10001-&gt;10001/udp, 0.0.0.0:8880-&gt;8880/tcp, :::8880-&gt;8880/tcp   unifi-controller-unifi-controller-1
b6b1733befc6   pihole/pihole:latest           &quot;/s6-init&quot;               25 minutes ago   Up 3 seconds (health: starting)   0.0.0.0:53-&gt;53/udp, :::53-&gt;53/udp, 0.0.0.0:53-&gt;53/tcp, 0.0.0.0:67-&gt;67/udp, :::53-&gt;53/tcp, :::67-&gt;67/udp, 0.0.0.0:9080-&gt;80/tcp, :::9080-&gt;80/tcp, 0.0.0.0:9443-&gt;443/tcp, :::9443-&gt;443/tcp                                                                                                                                                                                                                 pihole-pihole-1
47c751c5912b   nginx                          &quot;/docker-entrypoint.…&quot;   30 minutes ago   Up 3 seconds                      0.0.0.0:80-&gt;80/tcp, :::80-&gt;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:~ $

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

CC BY-SA 4.0
2023-08-17T13:29:45.490Z
Instead of ctrl+D, could you instead just do `exit` to logout?
mikequentel
<docker>
Docker containers are being restarted after logging in via SSH
com2ghz
# Docker containers are being restarted after logging in via SSH

(Asked by: username_0 on 2022-11-19)

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?

**Tags:** docker

> **Comments:**
> **username_1**: Instead of ctrl+D, could you instead just do `exit` to logout?  

---

## 1 answers

### Answer by username_0 on 2022-11-19. Score: 1 | Accepted answer

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`


---

