Cannot connect to containerized database due to port issues.
Hi. We're having issues when connecting to the containerized docker images for the backend. The problem we're getting is connection refused as the screen shot shows.
The ports we're using are the following:
In settings.py DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'DBtest2', 'USER': 'postgres', 'PASSWORD': 'super', 'HOST': '127.0.0.1', #db' tidigare 'PORT': '5432', #Port problem? Ändra till 5433? } }
In docker-comose.yml services: web: build: . command: python manage.py runserver 0.0.0.0:8000 expose: #Denna är ny!! - "80" ports: - "8000:8000" environment: - POSTGRES_DB=DBtest2 #Om du får port problem ändra till "5433:5432" - POSTGRES_PORT=5433 - POSTGRES_USER=postgres - POSTGRES_PASSWORD=super depends_on: - db db: image: postgres:latest environment: - POSTGRES_DB=DBtest2 #Om du får port problem ändra till "5433:5432" - POSTGRES_PORT=5433 - POSTGRES_USER=postgres - POSTGRES_PASSWORD=super ports: - "5433:5432" #Om du får port problem ändra till "5433:5432"
Dockerfile (for backend) FROM python:3.9
WORKDIR /tddd27
COPY requirements.txt /tddd27/
RUN pip install --no-cache-dir -r requirements.txt
COPY . /tddd27/
#This is the Port that Django is running on (default in Django projects) EXPOSE 8000
CMD ["python3", "manage.py", "runserver", "0.0.0.0:8000"]