My project is a basic API using Django and PostgreSQL. I've built Docker images before but I can not find any information on this, all I see is how to download an image with PostgreSQL but not how to build an image of my own project that uses a database. I previously tried to build an image but I got an error:
Is the server running on that host and accepting TCP/IP connections?
2023-07-18 18:22:33 connection to server at "localhost" (::1), port 5432 failed: Cannot assign requested address
What kind of configuring do I need to build this image? A resource with examples would be helpful as I can't seem to find anything.
Here is my Dockerfile:
FROM python:3
ENV PYTHONUNBUFFERED=1
WORKDIR /code
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
ENV PORT=8000
EXPOSE 8000
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
Here is my docker-compose.yml file, this is the same one that worked on a previous project but I assume I need to add PostgreSQL to it but I am unsure what specifically needs to be added:
services:
web:
build:
context: app
target: builder
ports:
- '8000:8000'