I cannot make a Sails container and a Postgress container to communicate. ping
-ing by the host names works, which means that the containers can “see” each other, but when I make calls to the database from the server app, I get connection refused
error, that is why I assume the problem is in the port exposure. Even by specifically exposing the port of the Postgres container, it still doesn’t work.
If I run the server app locally on the host machine, everything works fine, which makes me assume the exposure of the DB container port is all fine.
On Docker for Mac the docker0
interface, that underlies the default bridge
network, is not implemented, so I cannot use this network, to which the containers are subscribed by default. And I want the containers to communicate only internally, within the Docker env, and not use the host machine as middleware. That is why I had to create a custom network, to which to subscribe the containers.
Here is the docker-compose.yml
configuration:
version: '2'
services:
sails-test:
build: .
ports:
- "8001:1337"
volumes:
- ./app:/app
command: node app
container_name: sails-server
networks:
- default
postgresdata:
image: busybox
volumes:
- /var/lib/postgresql
container_name: sails-postgres-data
postgres:
image: postgres:latest
ports:
- "8002:5432"
expose:
- "5432"
volumes_from:
- postgresdata
container_name: sails-postgres
networks:
- default
networks:
default:
external:
name: test-network
Inspecting the test-network
shows that both containers are well subscribed to it.
I need to use a custom network, but not link
-ing, because I’ve got other containers, from separate compose
configurations, that I subscribe to the custom network, and thus link
-ing will not do the trick (since it’s useful only for containers that are spinned in the same compose
network).
Any ideas how to make these guys talk to each other?