I am trying to build a nodejs dashboard to monitor various things including the docker containers that are running on the local system. The dashboard is installed on the server where docker is running. All of my attempts to get the information away from docker on the cli hasn't worked.
I created a test container, good ol' nginx.
jamie@pop-os:~/Code/flightdeck$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1c9c36395abf nginx "/docker-entrypoint.…" 41 minutes ago Up 41 minutes 0.0.0.0:8181->80/tcp, :::8181->80/tcp crazy_chatterjee
However using any library such as dockerode or hitting the API directly gives me a result. For example.
jamie@pop-os:~/Code/flightdeck$ curl --unix-socket /var/run/docker.sock -X GET http://localhost/v1.43/containers/json
[]
I have tried as root, I have tried changing permissions to 777 on the docker socket. I cannot work it out. I was expecting an object with one container of information in it. Do you have any ideas?
My guess is you're having docker installed twice (once via the repository of your linux distro and once via an app like docker-desktop) and you're accessing the "wrong" docker daemon's socket.
You can confirm that with
It will state
"Containers":0,"ContainersRunning":0if that socket belongs to a docker daemon you're not actually using.Anyway, since
docker psseems to be working fine for you, check your environment variables if the actually used docker socket's path is set there.For docker-desktop that's usually
$HOME/.docker/desktop/docker.sock, if I'm not mistaken.However, I'm not sure if docker-desktop actually sets the path via environment or uses an alias/wrapper for the
dockercommand instead. (seetype dockerandwhich docker)If you can't find it there, here are some commands that may or may not list sockets that belong to docker: