Trying to run my django server in a docker, but the postgres port is already being used? When I run "docker-compose up", I receive this error:
django.db.utils.OperationalError: could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
ERROR: Service 'web' failed to build: The command '/bin/sh -c python manage.py migrate' returned a non-zero code: 1
sudo service postgresql status
returns:
9.6/main (port 5432): online
sudo lsof -nP | grep LISTEN
returns:
postgres 15817 postgres 3u IPv4 1022328 0t0 TCP 127.0.0.1:5432
I tried to run "sudo kill -9 15817", but docker-compose up still receives the same error.
Docker-compose.yml
version: '3'
services:
db:
image: postgres
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'stemletics',
'USER': 'stemleticsadmin',
'PASSWORD': 'changeme',
'HOST': '127.0.0.1', # set in docker-compose.yml
'PORT': 5432 # default postgres port
}
}

network_mode: "host"to the django service in the docker-compose file.