docker daemon stops running when no user is signed in (on debian)

I did:

sudo systemctl enable docker.service
sudo systemctl enable containerd.service

So why isn’t docker running when my cron script runs?

$ cat /etc/group
...
admin:x:1000:
docker:x:997:admin
...

$ crontab -l -u admin
...
40 14 * * * /home/admin/dockerTest.sh

$ cat dockerTest.sh 
echo $(date) >>out.txt
docker run hello-world >>/home/admin/out.txt 2>&1

$ cat out.txt
Wed Jul 17 14:40:01 EDT 2024
docker: Cannot connect to the Docker daemon at unix:///run/user/1000/docker.sock. Is the docker daemon running?.
See 'docker run --help'.

If I run dockerTest.sh while I’m signed in, or even cron runs it while I’m signed in, it works (because the daemon is running). So I think I just need to keep docker running somehow. Should I just run some throwaway container or something to keep docker loaded? What am I doing wrong?

My guess is that your cronjob is using a different context so it needs a different socket. The one in the error message must be a rootless Docker socket

Or if you want to use the rootless Docker, you will need to enable the linger mode

https://docs.docker.com/engine/security/rootless/#daemon

but then you would not need to enable the global dockerd and containerd services

1 Like

sudo loginctl enable-linger admin fixed it! Thank you!

It might be nice to have this documentation link to the solution for docker-rootless: