Hi guys, im new to docker and I am trying to it to dockerize a Django app - which I intend to use as a web server - and a Postgres database.
This is my docker file for the Django app:
FROM python:3.10
EXPOSE 5001
# set working directory
WORKDIR /app
# build dependencies
COPY requirements.txt .
RUN pip install -r requirements.txt
# copy project
COPY . .
CMD ["python", "manage.py", "runserver", "0.0.0.0:5001"]
This is my docker-compose.yml file:
version: '4.12'
services:
db:
image: postgres:latest
restart: unless-stopped
ports:
- '5432:5432'
environment:
POSTGRES_PASSWORD: "${POSTGRES_PWD}"
POSTGRES_USER: "${POSTGRES_USER}"
POSTGRES_DB: hadis
volumes:
- ./db:/var/lib/postgresql/data
app:
image: hadis-backend
build: app
ports:
- '5001:5001'
environment:
DATABASE_URL: postgres://postgres:postgres@db:5431/postgres
volumes:
- ./app:/app
volumes:
db:
driver: local
This is the output I am getting:
[+] Running 14/14
⠿ db Pulled 29.6s
⠿ df8e44b0463f Pull complete 15.2s
⠿ b754b0988cff Pull complete 15.3s
⠿ ad5356093597 Pull complete 15.4s
⠿ f89869ca900b Pull complete 15.5s
⠿ 47843a81e9ab Pull complete 15.7s
⠿ 07e62452bcf1 Pull complete 15.8s
⠿ da41c6e7f3d3 Pull complete 15.8s
⠿ 2dc9a0774b1e Pull complete 15.9s
⠿ d39a10864579 Pull complete 26.9s
⠿ 0505c43f4e5e Pull complete 26.9s
⠿ f62a17755f47 Pull complete 27.0s
⠿ 8bd6b9082119 Pull complete 27.0s
⠿ 245f8dc49705 Pull complete 27.1s
[+] Running 3/3
⠿ Network hadis-backend_default Created 0.0s
⠿ Container hadis-backend-app-1 Created 0.3s
⠿ Container hadis-backend-db-1 Created 0.3s
Attaching to hadis-backend-app-1, hadis-backend-db-1
I used docker build app/ -t hadis-backend
to build the images and then docker compose up
to start the containers. I cannot connect to 0.0.0.0:5001 in my browser. I am kind of stuck and don’t know how to move on from here since I am not getting any error messages. I hope to find some help here. Thanks a lot!