I can't get one of my containers (service) to connect to the postgres database container through docker. It seems to be complaining about using the wrong database...(I'm using node.js with the 'pg' and 'pg-promise' libraries.).
My postgres connection info
const pg = require('pg');
const pgp = require('pg-promise')();
var config = {
user: 'root',
password: 'myPassword',
database: 'myDb',
host: 'database',
port: 5432
};
const db = pgp(config);
Error when docker attempts to connect to the database
{ Error: getaddrinfo ENOTFOUND database database:5432
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
code: 'ENOTFOUND',
errno: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'database',
host: 'database',
port: 5432 }
I know that by default the container has the same hostname as the service name, but that didn't work (my service name is "database"). Anything I'm missing?
docker-compose.yml
version: '3'
services:
myapp:
build: My-App/
depends_on:
- 'database'
ports:
- '5000:5000'
database:
image: postgres:11.5
databasecontainer ?