Docker Ports are not available exposing port TCP 0.0.0.0:5432 -> 0.0.0.0:0

Viewed 65

I'm new to Docker, and I'm trying to dockerize my Django application. My compose file looks like the following:

docker-compose.yml

version: '3'

services:
  web:
    build:
      context: .
      dockerfile: Dockerfile
    env_file:
      - csgo.env
    volumes:
      - .:/code
    ports:
      - 8000:8000
    depends_on:
      - db

  db:
    image: postgres:13
    restart: always
    # Optional: Map the container port to a host port to be able to connect with a local db client 
    ports:
      - 5432:5432
    env_file:
      - csgo.env
    environment:
      - POSTGRES_PASSWORD=db_password
      - DB_NAME=db_name
      - DB_USER=db_user
      - DB_PASSWORD=db_password
      - DB_HOST=localhost
    volumes:
      - ./db/psql-init/db.sql:/docker-entrypoint-initdb.d/db.sql
      - postgres_data:/var/lib/postgresql/data/

volumes:
  postgres_data:

I try to docker-compose up but this error occurs. I wonder what could be the problem? Why it says the PORT is already in use? Error

[+] Running 4/4
 ⠿ Network csgo_default         Created                                                                                               0.0s
 ⠿ Volume "csgo_postgres_data"  Created                                                                                               0.0s
 ⠿ Container csgo-db-1          Created                                                                                               0.1s
 ⠿ Container csgo-web-1         Created                                                                                               0.1s
Attaching to csgo-db-1, csgo-web-1
Error response from daemon: Ports are not available:
 exposing port TCP 0.0.0.0:5432 -> 0.0.0.0:0: listen tcp 0.0.0.0:5432:
 bind: address already in use
1 Answers

Solved: Listed all ports of postgres (Mac):

sudo lsof -i -P | grep LISTEN | grep :5432
postgres   9785              postgres    7u  IPv6 0xd0180dc2abc35a25      0t0    TCP *:5432 (LISTEN)
postgres   9785              postgres    8u  IPv4 0xd0180dc778b0fe35      0t0    TCP *:5432 (LISTEN)

Killed all these processes (How do I close an open port from the terminal on the Mac?)

Related