Created my service using the following command with docker:
docker service create --mount type=bind,src=/tmp/postgres,dst=/var/lib/postgresql/data --name dev_db --network mynetwork -p 5432:5432 -d postgres
The problem is that if I don't use the overlay network
--network, I can connect to this docker instance from another host by just using the simple postgresql client:
psql -h (ipofthehost) mydatabase -Umydatabase
but now that I want to connect to it from another host I get this error:
psql: could not connect to server: Connection refused Is the server running on host "ipofdehost" and accepting TCP/IP connections on port 5432?
Which is telling me that it might be running but it can't see it. I verified if the service is running with:
docker service ls ID NAME MODE REPLICAS IMAGE PORTS 8hr0qwtca230 dev_db replicated 1/1 postgres:latest *:5432->5432/tcp
I verified with ss to see if the service is listening:
State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:22 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 :::22 :::* LISTEN 0 128 :::5432 :::* LISTEN 0 128 :::12376 :::* LISTEN 0 100 ::1:25 :::* LISTEN 0 128 :::443 :::*
It seems like it is listening because of the line:
:::5432, but for me that seems like it is only for ipv6 connections, so how can I make it to listen for ipv4 connections?, all I have changed was that I connected that node to the overlay network so I don't understand why if I made it to expose the ports is not making available publicly.