Docker Community Forums

Share and learn in the Docker community.

Docker swarm access manager API from container

Hello everyone,

Is it possible to access the HTTP API of the swarm manager from within a container anywhere on the swarm on any node?
I want to get information about running containers from within a container.

Only if you did bind a tcp port on your manager nodes.

If you didn’t, your only chance is to bind-mount the docker.sock on manager nodes and fire your api queries against the docker.sock inside the container.

Nothing I can’t still do. Can you maybe explain the first solution a little more?

If nothing works I had the idea to try to use sth. like nginx as a man in the middle, which runs inside a container, which is connected to the swarm network, and forwards all requests to the actual docker API.

You might want to take a look at the docks:

Okay I have my manager node configured that it exposes port 2375 for insecure interaction with the docker api. When I’m inside a container running on the manager I can access it using the url host.docker.internal:2375.
But how would be a good way to also access it from containers of other nodes? There host.docker.internal will not point to my manager node.

Is there a reason you don’t use the hostname of your machine to access the endpoint? If your local dns server is able to resolve the hostname, your container should be able to do the same. Docker for Windows?

If this doesn’t work, a worakaround coulbe be to use a placement constraint to limit the deployment to the manager node(s).

Okay I found a solution, which is basically what I was searching for.

This, combined with an overlay network, gives every container in the swarm access to the docker api, if it is joined to the right overlay network and has the right certificates.

Great finding. Still, you will want to add a placement constraint to the service :slight_smile: