Docker is running a container but no output from the API shows them

127 views Asked by At

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?

1

There are 1 answers

4
Jay On

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

curl --unix-socket /var/run/docker.sock -X GET http://localhost/info

It will state "Containers":0,"ContainersRunning":0 if that socket belongs to a docker daemon you're not actually using.

Anyway, since docker ps seems to be working fine for you, check your environment variables if the actually used docker socket's path is set there.

env | grep -i docker

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 docker command instead. (see type docker and which docker)

If you can't find it there, here are some commands that may or may not list sockets that belong to docker:

ss -x | grep -i docker | grep -v containerd

sudo find /run "$HOME/.docker" -name docker.sock

sudo find /run "$HOME/.docker" -type s -ipath '*docker*' -not -name 'containerd*.sock*'