Some docker containers need manual start after host reboot
from OneCardboardBox@lemmy.sdf.org to selfhosted@lemmy.world on 24 Oct 23:40
https://lemmy.sdf.org/post/24181670

I generally let my server do its thing, but I run into an issue consistently when I install system updates and then reboot: Some docker containers come online, while others need to be started manually. All containers were running before the system shut down.

Host is running Ubuntu Noble

Most of these containers were migrated from my previous server, and this issue never manifested.

I wonder if anyone has ideas for what to look for?

SOLVED

The issue was that docker was starting before my NFS mount point was ready, and the containers which depended on it were crashing.

Symptoms: journalctl -b0 -u docker showed the following log lines (-b0 means to limit logs to the most recent boot):

level=error msg="failed to start container" container=fe98f37d1bc3debb204a52eddd0c9448e8f0562aea533c5dc80d7abbbb969ea3 error="error while creating mount source path '/mnt/nas/REDACTED': mkdir /mnt/nas/REDACTED: operation not permitted"
...
level=warning msg="ShouldRestart failed, container will not be restarted" container=fe98f37d1bc3debb204a52eddd0c9448e8f0562aea533c5dc80d7abbbb969ea3 daemonShuttingDown=true error="restart canceled" execDuration=5m8.349967675s exitStatus="{0 2024-10-29 00:07:32.878574627 +0000 UTC}" hasBeenManuallyStopped=false restartCount=0

I had previously set my mount directory to be un-writable if the NFS were not ready, so this lined up with my expectations.

I couldn’t remember how systemd names mount points, but the following command helped me find it: systemctl list-units -t mount | grep /mnt/nas

It gave me mnt-nas.mount as the name of the mount unit, so then I just added it to the After= and Requires= lines in my /etc/systemd/system/docker.service file:

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.service containerd.service time-set.target mnt-nas.mount
Wants=network-online.target containerd.service
Requires=docker.socket mnt-nas.mount
...

#selfhosted

threaded - newest

CameronDev@programming.dev on 24 Oct 23:45 next collapse

Can you make your docker service start after the NFS Mount to rule that out?

A restart policy only takes effect after a container starts successfully. In this case, starting successfully means that the container is up for at least 10 seconds and Docker has started monitoring it. This prevents a container which doesn’t start at all from going into a restart loop.

docs.docker.com/…/start-containers-automatically/…

If your containers are crashing before the 10 timeout, then they won’t restart.

OneCardboardBox@lemmy.sdf.org on 29 Oct 00:11 collapse

Yep, the problem was that docker started before the NFS mount. Adding the dependency to my systemd docker unit did the trick!

CameronDev@programming.dev on 29 Oct 01:03 collapse

Excellent, thanks for the update!

just_another_person@lemmy.world on 25 Oct 00:15 next collapse

Add a healthcheck to test the mount directory. If it’s deemed unhealthy, the container should restart until it passes. If your NFS mount is automounting properly, you should fix that though.

schizo@forum.uncomfortable.business on 25 Oct 00:18 next collapse

I hate to be that guy, but uh, what do the logs say?

The container logs would probably be most useful since you should (probably) be able to tell if they’re having issues starting and/or simply not attempting to launch at all.

mbirth@lemmy.ml on 25 Oct 00:52 next collapse

Put that mount point into the compose file(s). You can define volumes with type nfs and basically have Docker-Compose manage the mounts.

WhyJiffie@sh.itjust.works on 25 Oct 02:06 collapse

I have recently discovered what was causing this to me for years. It was IP specific port bindings. Ports of a few containers were only bound for the LAN IP of the system, but if DHCP couldn’t obtain an IP until the Docker service started its startup, then those containers couldn’t be started at all, and Docker in it’s wisdom won’t bother with retrying.

The reasons to move my compose stacks to separate systemd services are counting.