Skip to content

Commit 11ad034

Browse files
committed
Add docker-compose files
1 parent affa11a commit 11ad034

File tree

2 files changed

+50
-13
lines changed

2 files changed

+50
-13
lines changed

backend/Dockerfile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Use an official Python runtime as a base image
2+
FROM python:3.12
3+
4+
ENV PYTHONUNBUFFERED=1
5+
6+
# Set the working directory inside the container
7+
WORKDIR /app
8+
9+
# Install system dependencies
10+
RUN apt-get update && \
11+
apt-get install -y --no-install-recommends gcc curl gnupg2 && \
12+
apt-get clean && \
13+
rm -rf /var/lib/apt/lists/*
14+
15+
# Install Poetry
16+
RUN curl -sSL https://install.python-poetry.org | python3 -
17+
18+
# Add Poetry to PATH
19+
ENV PATH="${PATH}:/root/.local/bin"
20+
21+
# Copy only the pyproject.toml and poetry.lock to leverage Docker cache
22+
COPY pyproject.toml poetry.lock /app/
23+
24+
# Install project dependencies
25+
RUN poetry config virtualenvs.create false && poetry install --no-interaction --no-ansi
26+
27+
# Copy the entire Django project to the working directory
28+
COPY . /app/
29+
30+
# Expose the port your application will run on
31+
EXPOSE 8000
32+
33+
# Command to run the Django server
34+
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

docker-compose.yml

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
version: '3.8' # Use the version of Docker Compose that you need
1+
version: "3.9" # Use the version of Docker Compose that you need
22

33
services:
4-
postgresdb:
5-
image: postgres:latest # Use the latest PostgreSQL image
6-
container_name: postgresdb # Name your container
4+
db:
5+
image: postgres # Use the latest PostgreSQL image
6+
volumes:
7+
- ./data/db:/var/lib/postgresql/data
78
environment:
8-
POSTGRES_USER: yourusername # Set the username for the PostgreSQL database
9-
POSTGRES_PASSWORD: yourpassword # Set the password for the PostgreSQL database
10-
POSTGRES_DB: yourdatabase # Set the name of the database
9+
- POSTGRES_USER=yourusername # Set the username for the PostgreSQL database
10+
- POSTGRES_PASSWORD=yourpassword # Set the password for the PostgreSQL database
11+
- POSTGRES_DB=yourdatabase # Set the name of the database
1112
ports:
1213
- "5432:5432" # Map the PostgreSQL port to the host
14+
backend:
15+
build: ./backend
16+
command: python manage.py runserver 0.0.0.0:8000
1317
volumes:
14-
- postgres_data:/var/lib/postgresql/data # Persist the data using a named volume
15-
16-
volumes:
17-
postgres_data:
18-
driver: local # Use the local driver for the volume
19-
18+
- .:/code
19+
ports:
20+
- "8000:8000"
21+
depends_on:
22+
- db

0 commit comments

Comments
 (0)