Network attached on second start only

Hi, I#ve got a strange effect on my Raspberry Pi Docker installation.
OS: Linux rpi 6.6.74+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.6.74-1+rpt1 (2025-01-27) aarch64 GNU/Linux
Docker:

Client: Docker Engine - Community
 Version:           27.5.1
 API version:       1.47
 Go version:        go1.22.11
 Git commit:        9f9e405
 Built:             Wed Jan 22 13:41:25 2025
 OS/Arch:           linux/arm64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          27.5.1
  API version:      1.47 (minimum version 1.24)
  Go version:       go1.22.11
  Git commit:       4c9b3b0
  Built:            Wed Jan 22 13:41:25 2025
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.7.25
  GitCommit:        bcc810d6b9066471b0b6fa75f557a15a1cbf31bb
 runc:
  Version:          1.2.4
  GitCommit:        v1.2.4-0-g6c52b3f
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

I have Piwigo installed along with MariaDB

CONTAINER ID   IMAGE                               COMMAND                  CREATED        STATUS        PORTS                                              NAMES
a0622f66cde2   lscr.io/linuxserver/piwigo:latest   "/init"                  13 hours ago   Up 13 hours   443/tcp, 0.0.0.0:8080->80/tcp, [::]:8080->80/tcp   piwigo
e927a707bf06   adminer                             "entrypoint.sh php -…"   13 hours ago   Up 13 hours   0.0.0.0:33066->8080/tcp, [::]:33066->8080/tcp      piwigo-adminer-1
af419798bcb0   linuxserver/mariadb                 "/init"                  13 hours ago   Up 13 hours   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp          mariadb

It works fine with the following compose.yml

services:

  mariadb:
    image: linuxserver/mariadb
    container_name: mariadb
    environment:
      - PUID=1000
      - PGID=1000
      - MYSQL_ROOT_PASSWORD=xyz
      - TZ=Europe/Berlin
    volumes:
      - /opt/dev/docker/mariadb/config:/config
    ports:
      - 3306:3306
    restart: unless-stopped

  piwigo:
    image: lscr.io/linuxserver/piwigo:latest
    container_name: piwigo
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Europe/Berlin
    volumes:
      - /opt/dev/docker/piwigo/config:/config
      - /opt/piwigo/gallery:/gallery
    ports:
      - 8080:80
    restart: unless-stopped

  adminer:
    image: adminer
    restart: always
    ports:
      - 33066:8080

BUT strange thing is: When I reboot the Raspberry and do a docker compose up -d, it doesn’t announce the network as being started:

pi@rpi:/opt/dev/docker/piwigo $ docker compose up -d
[+] Running 3/3
 ✔ Container piwigo            Running                                                                                                                                                                        
 ✔ Container mariadb           Running                                                                                                                                                                        
 ✔ Container piwigo-adminer-1  Running                                                                                                                                                                        
pi@rpi:/opt/dev/docker/piwigo $

..and from my LAN, the call of piwigo rpi:8080 is being redirected to http://rpi:8080/install.php
docker network list shows the piwigo_default network and inspect shows it too. Looks good. The problem can be solved by doing a docker compose down. Then it announces the network as going down!

pi@rpi:/opt/dev/docker/piwigo $ docker compose down
[+] Running 4/4
 ✔ Container piwigo               Removed                                                                                                                                                                     
 ✔ Container mariadb              Removed                                                                                                                                                                     
 ✔ Container piwigo-adminer-1     Removed                                                                                                                                                                    
 ✔ Network piwigo_default  Removed                                                                                                                                                                     
pi@rpi:/opt/dev/docker/piwigo $

And now, with the second docker compose up -d, the network is announced and piwigo is accesible from LAN.

pi@rpi:/opt/dev/docker/piwigo $ docker compose up -d
[+] Running 4/4
 ✔ Network piwigo_default  Created
 ✔ Container piwigo-adminer-1     Started
 ✔ Container piwigo               Started
 ✔ Container mariadb              Started
pi@rpi:/opt/dev/docker/piwigo $

This is exactly reproducable. I tried putting the network explicitly in the compose.yml with no effect. I still need to start compose twice to have the installation being accesible from LAN.

Any idea how to solve that issue?
Thank you, fm

If you deployed the compose project and don’t remove the network afterward, like docker compose down does, then there is nothing strange about it. Networks are not removed, just because you start your computer.

OK…that explains, why the network is not “created/started” after reboot. THank you for the insight. But the major issue is, that after reboot and compose up the application (piwigo) is “confused” (redirecting me to to http://rpi:8080/install.php) while it works fine after compose down and a 2nd compose up. It seems, that the network has to be removed by compose down and recreated by compose up to work cleanly.

Can you share what makes you think the container network would be responsible for how the application inside the container behaves? I

You could test if it makes a difference whether a fresh created container is used, or a previously stopped container is restarted. While the container is running, add a dummy variable to your environment block in the compose file and perform a docker compose up -d to force the re-creation of the container.

I can’t tell, that the network is responsible. What I can tell is, that after reboot and compose up piwigo doesn’t work. After a compose down and up again, it works fine. Please keep in mind, that I’m only beginner in docker things and probably miss some fundamental concept of it, which might be obvious to experienced users.

Solution: I found out that docker containers are up and running directly after reboot without having been started explicitly and no compose up. That might be due to “restart unless-stopped”. The problem will most probably be linked to veracrypt containers not present before being mounted by hand. Hence if docker starts automatically after reboot, some host volumes are not ready-for-use and piwigo fails. The whole time I thought, unless-stopped would mean unless-stopped-or-host-is-rebooted. I mounted the veracrypt volumes after reboot and therefore they were not present upon auto-docker-up, but on the secoand, manual docker up.

I changed restart into restart=no. Now after reboot, docker ps is empty. And after mounting veracrypt volumes and then compose up, everything works fine on the first run.

I am glad you found the root cause and found a solution that works for you.

Not sure if it fits your use case, but a 5-minutes google search helped me find this blog post that describes how to leverage /etc/crypttab to mount veracrypt containers on boot.