Okay, I think I've found a better root cause for the issue where docker ps
shows an empty list, but the containers are known to be running, at least on Ubuntu Server 22.04 where maybe Docker was installed at initial installation (via Snap?) and again later via the standard instructions (via apt).
The answer comes from here: https://forums.docker.com/t/ubuntu-22-04-unexpected-docker-socket-behaviour-after-boot/134626/3
The gist is that Docker is installed from 2 sources: apt + snap, One starts at boot, and the other replaces it (but doesn't know about the running containers).
Check if this is the case by running these commands:
dpkg -l | grep docker
snap list | grep docker
If both show docker then this might be the issue.
Remove the snap install with:
sudo snap remove docker
Once I did the above I received the following output:
$> docker ps
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
But then I did:
$> sudo systemctl restart docker.socket
$> docker ps
CONTAINER ID IMAGE ...
ffe52... container ...
And saw my containers.
Also, upon reboot, a simple docker ps
shows the expected containers instead of an empty list.