0

I would like to create a docker-compose that launches 2 containers: one my NodeJS API and the other a Postgresql DB. But I don't want the database to be accessible through the internet but only the API because only the API should contact it and no one else. I created a network and didn't publish the DB port (5432) but when I try to run my docker-compose I get an error which I don't understand.

Here is the error during docker-compose up : enter image description here

My Dockerfile :

FROM node:16.15.0
WORKDIR /app
COPY ["package.json", "package-lock.json*", "./"]
RUN npm install
COPY . .
EXPOSE 3001
CMD npm start

And my docker-compose :

version: "3"

services:
    api_nodejs:
        build: .
        depends_on:
            - db
        ports:
            - ${APP_PORT}:3001
        command: npm start
        volumes:
            - .:/app/
            - /app/node_modules
        networks:
            my_network:
                ipv4_address: 192.168.0.1

    db:
        image: postgres:14.3
        restart: always
        environment:
            - POSTGRES_DB=${DB_NAME}
            - POSTGRES_USER=${DB_USERNAME}
            - POSTGRES_PASSWORD=${DB_PASSWORD}
        networks:
            my_network:
                ipv4_address: 192.168.0.2

networks:
    my_network:
        ipam:
            driver: default
            config:
                - subnet: 192.168.0.0/24

1
  • You seem to have attached an image file to your question in place of the error text. Can you edit the question to include the actual text of the error? Commented May 20, 2022 at 21:38

1 Answer 1

1

Your Error "Address already in use"

you give your container api_nodejs the IP 192.168.0.1, this IP is mostly used by your router.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.