I have a Swarm running with a Postgres database as part of it. I’m trying to figure out how to connect to the database so I can query it. Back when I used Compose in a previous setup I was able to expose the port to the host and then SSH into the host and just connect over a tunnel. However with Swarm it doesn’t seem possible to expose a container to the host as well.
So if I have a swarm entry visible on the host as
root@do-prod-node-3:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ac4a573c2c14 postgres:9.6 "/docker-entrypoint.s" 7 minutes ago Up 7 minutes 5432/tcp authdb.1.7yg3gx1naqhti3lpzy1pu9qpn
I can’t access this container as is from the host (that I’m aware of). If I use the
publish-add option of Swarm then I can access the container… however it is also exposed on the public interface.
What is the best way to securely connect to the database from the host and only the host?