A
A
Alexander Bondarenko2021-12-03 13:42:29
Nginx
Alexander Bondarenko, 2021-12-03 13:42:29

Why can't I run node js along with nginx on docker-compose?

Hello everyone, tell me what the error is, I'm trying to set up a project on express.js, I'm trying to deploy on docker'e, I can't connect nginx, an error occurs that the port is busy, how can I fix it?

version: '3.8'

services:

  backend:
    container_name: my-server
    image: my-server:0.2
    build: 
      context: .
    ports:
      - "80:5001"
    environment:
      - EXTERNAL_PORT=5001
    depends_on:
      - node_db
      
  node_db:
    container_name: my_db
    image: "postgres:13.5"
    ports:
      - "5432:5432"
    volumes:
      - nps_data:/var/lib/postgresql/data
    environment:
      - DB_NAME=name
      - DB_USER=admin
      - DB_PASSWORD=password
      - DB_HOST=my_db
      - DB_PORT=5432
      - POSTGRES_PASSWORD=mysecretpassword

  nginx:
    image: nginx:1.19
    volumes:
      - .\nginx:/etc/nginx/conf.d
    ports:
      - 80:80
      - 443:443
    env_file:
      - .env
    depends_on:
      - backend

volumes:
  nps_data: {}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nowm, 2021-12-03
@bond_1013

Replace - "80:5001"with - "5001:5001"in the services.backend block and it should work. Also, you need to make sure in the code of the NodeJS project itself that you are only listening on port 5001 and not touching ports 80 and 443.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question