Docker Community Forums

Share and learn in the Docker community.

Connect ECONNREFUSED server_1 docker compose

I create docker-compose.yml to launch the app locally in docker container:
version: ‘3’

services: 
    server:
        image: node:lts-alpine3.13
        working_dir: /app
        volumes:
            - .:/app
        environment: 
            - PORT=5000
            - DB_HOST=db
            - DB_USERNAME=postgres
            - DB_PASSWORD=postgres
            - DB_DEV_NAME=mydb
            - DB_TEST_NAME=mydb_test
        depends_on: 
            - db
        command: npm run migrate:latest && npm start
        ports: 
            - '5000:5000'
    
    db:
        image: postgis/postgis:13-3.1-alpine
        environment: 
            - POSTGRES_USER=postgres
            - POSTGRES_PASSWORD=postgres
            - POSTGRES_DB=mydb
        ports:
            - '5432:5432'

I got this error:
db_1 | waiting for server to start…2021-04-14 18:33:33.819 UTC [36] LOG: starting PostgreSQL 13.2
db_1 | 2021-04-14 18:33:33.921 UTC [36] LOG: listening on Unix socket “/var/run/postgresql/.s.PGSQL.5432”
db_1 | 2021-04-14 18:33:34.174 UTC [37] LOG: database system was shut down at 2021-04-14 18:33:31 UTC
db_1 | 2021-04-14 18:33:34.245 UTC [36] LOG: database system is ready to accept connections
db_1 | done
db_1 | server started
db_1 | CREATE DATABASE
db_1 |
db_1 |
db_1 | /usr/local/bin/docker-entrypoint.sh: sourcing /docker-entrypoint-initdb.d/10_postgis.sh
server_1 | Working directory changed to /app/src/config
server_1 | Using environment: development
db_1 | CREATE DATABASE
db_1 | Loading PostGIS extensions into template_postgis
db_1 | CREATE EXTENSION
db_1 | CREATE EXTENSION
db_1 | CREATE EXTENSION
db_1 | CREATE EXTENSION
db_1 | Loading PostGIS extensions into mydb
server_1 | Error: connect ECONNREFUSED 172.30.0.2:5432
server_1 | at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
server_1 | npm ERR! code ELIFECYCLE
server_1 | npm ERR! errno 1
server_1 | npm ERR! project@1.0.0 rollback: knex migrate:rollback --knexfile ./src/config/knexfile.js
server_1 | npm ERR! Exit status 1
server_1 | npm ERR!
server_1 | npm ERR! Failed at the adotmob-homework@1.0.0 rollback script.
server_1 | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
server_1 |
server_1 | npm ERR! A complete log of this run can be found in:
server_1 | npm ERR! /root/.npm/_logs/2021-04-14T18_33_43_899Z-debug.log
server_1 | npm ERR! code ELIFECYCLE
server_1 | npm ERR! errno 1
server_1 | npm ERR! project@1.0.0 migrate:latest: npm run rollback && npm run migrate "&&" "npm" "start"
server_1 | npm ERR! Exit status 1
server_1 | npm ERR!
server_1 | npm ERR! Failed at the project@1.0.0 migrate:latest script.
server_1 | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
server_1 |
server_1 | npm ERR! A complete log of this run can be found in:
server_1 | npm ERR! /root/.npm/_logs/2021-04-14T18_33_43_974Z-debug.log
db_1 | CREATE EXTENSION
server_1 exited with code 1
db_1 | CREATE EXTENSION
db_1 | CREATE EXTENSION
db_1 | CREATE EXTENSION
db_1 |
db_1 | waiting for server to shut down…2021-04-14 18:33:56.915 UTC [36] LOG: received fast shutdown request
db_1 | .2021-04-14 18:33:56.989 UTC [36] LOG: aborting any active transactions
db_1 | 2021-04-14 18:33:56.990 UTC [36] LOG: background worker “logical replication launcher” (PID 43) exited with exit code 1
db_1 | 2021-04-14 18:33:56.991 UTC [38] LOG: shutting down
db_1 | …2021-04-14 18:33:59.296 UTC [36] LOG: database system is shut down
db_1 | done
db_1 | server stopped
db_1 |
db_1 | PostgreSQL init process complete; ready for start up.
db_1 |
db_1 | 2021-04-14 18:33:59.499 UTC [1] LOG: starting PostgreSQL 13.2 on x86_64-pc-linux-musl, compiled by gcc (Alpine 10.2.1_pre1) 10.2.1 20201203, 64-bit
db_1 | 2021-04-14 18:33:59.499 UTC [1] LOG: listening on IPv4 address “0.0.0.0”, port 5432
db_1 | 2021-04-14 18:33:59.499 UTC [1] LOG: listening on IPv6 address “::”, port 5432
db_1 | 2021-04-14 18:33:59.621 UTC [1] LOG: listening on Unix socket “/var/run/postgresql/.s.PGSQL.5432”
db_1 | 2021-04-14 18:33:59.775 UTC [57] LOG: database system was shut down at 2021-04-14 18:33:59 UTC
db_1 | 2021-04-14 18:33:59.796 UTC [1] LOG: database system is ready to accept connections