I have a basic Django project that I have put into a docker container.
Currently I have it running on https locally just for the development phase because it is a requirement.
When I run my program without docker it opens successfully on https://127.0.0.1:8000. Which is the address the message says its currently running on.
But when I use the same logic on my docker container after running docker-compose up the container compiles but I am unable to load the web page. When I try to run the address from the docker container I just get the generic site cannot be reached error.
Link I used to get https during development:
Docker-compose.yml
version: "3.8"
services:
django:
build: .
container_name: frontend
command: python manage.py runserver_plus --cert-file cert.pem --key-file key.pem
volumes:
- .:/usr/src/app
ports:
- "8000:8000"
depends_on:
- pgdb
pgdb:
image: postgres
container_name: backend
environment:
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
Dockerfile
FROM python:3.12.3
ENV PYTHONUNBUFFERED=1
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install django
RUN pip install -r requirements.txt
settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'location',
'rest_framework',
'django_extensions',
]
I tried to change the port number but it still didn’t work.