Docker Community Forums

Share and learn in the Docker community.

Docker Compose networks

Hello I have a problem in my nodejs project with graphql and typescript using the image of node-alpine and postgress

i have this on my

env:

SERVER_PORT=4000

DB_HOST=ci-postgres

DB_PORT=5432

DB_USER=spirit

DB_PASS=api

DB_NAME=emasa_ci

dockerFile:

#building code

FROM node:lts-alpine

RUN mkdir -p /home/node/api/node_modules && chown -R node:node /home/node/api

WORKDIR /home/node/api

COPY ormconfig.json .env package.json yarn.* ./

USER node

RUN yarn

COPY --chown=node:node . .

EXPOSE 4000

CMD ["yarn", "dev"]

docker compose:

version: '3.7'

services:

  ci-api:

    build: .

    container_name: ci-api

    volumes:

      - .:/home/node/api

      - /home/node/api/node_modules

    ports:

      - '${SERVER_PORT}:${SERVER_PORT}'

    depends_on:

      - ci-postgres

    networks:

      - ci-network

  ci-postgres:

    image: postgres:12

    container_name: ci-postgres

    ports:

      - '${DB_PORT}:5432'

    environment:

      - ALLOW_EMPTY_PASSWORD=no

      - POSTGRES_USER=${DB_USER}

      - POSTGRES_PASSWORD=${DB_PASS}

      - POSTGRES_DB=${DB_NAME}

    volumes:

      - ci-postgres-data:/data

    networks:

      - ci-network

volumes:

  ci-postgres-data:

networks:

  ci-network:

    driver: bridge

and this is my ormconfig ( typeorm) for my postgres:

{

  "type": "postgres",

  "host": "${DB_HOST}",

  "port": 5432,

  "username": "${DB_USER}",

  "password": "${DB_PASS}",

  "database": "${DB_NAME}",

  "synchronize": true,

  "logging": false,

  "entities": ["dist/src/entity/**/*.js"],

  "migrations": ["dist/src/migration/**/*.js"],

  "subscribers": ["dist/src/subscriber/**/*.js"],

  "cli": {

    "entitiesDir": "dist/src/entity",

    "migrationsDir": "dist/src/migration",

    "subscribersDir": "dist/src/subscriber"

  }

}

but i got this error:

node:51) UnhandledPromiseRejectionWarning: Error: getaddrinfo ENOTFOUND ${DB_HOST}
ci-api         |     at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:66:26)

I don’t know why I created a network and used the name of my postgres img on my host and I still have an error