Skip to content

Commit

Permalink
Add docker-compose files
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmyjuareza committed Jun 29, 2024
1 parent affa11a commit 11ad034
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 13 deletions.
34 changes: 34 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Use an official Python runtime as a base image
FROM python:3.12

ENV PYTHONUNBUFFERED=1

# Set the working directory inside the container
WORKDIR /app

# Install system dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends gcc curl gnupg2 && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Install Poetry
RUN curl -sSL https://install.python-poetry.org | python3 -

# Add Poetry to PATH
ENV PATH="${PATH}:/root/.local/bin"

# Copy only the pyproject.toml and poetry.lock to leverage Docker cache
COPY pyproject.toml poetry.lock /app/

# Install project dependencies
RUN poetry config virtualenvs.create false && poetry install --no-interaction --no-ansi

# Copy the entire Django project to the working directory
COPY . /app/

# Expose the port your application will run on
EXPOSE 8000

# Command to run the Django server
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
29 changes: 16 additions & 13 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
version: '3.8' # Use the version of Docker Compose that you need
version: "3.9" # Use the version of Docker Compose that you need

services:
postgresdb:
image: postgres:latest # Use the latest PostgreSQL image
container_name: postgresdb # Name your container
db:
image: postgres # Use the latest PostgreSQL image
volumes:
- ./data/db:/var/lib/postgresql/data
environment:
POSTGRES_USER: yourusername # Set the username for the PostgreSQL database
POSTGRES_PASSWORD: yourpassword # Set the password for the PostgreSQL database
POSTGRES_DB: yourdatabase # Set the name of the database
- POSTGRES_USER=yourusername # Set the username for the PostgreSQL database
- POSTGRES_PASSWORD=yourpassword # Set the password for the PostgreSQL database
- POSTGRES_DB=yourdatabase # Set the name of the database
ports:
- "5432:5432" # Map the PostgreSQL port to the host
backend:
build: ./backend
command: python manage.py runserver 0.0.0.0:8000
volumes:
- postgres_data:/var/lib/postgresql/data # Persist the data using a named volume

volumes:
postgres_data:
driver: local # Use the local driver for the volume

- .:/code
ports:
- "8000:8000"
depends_on:
- db

0 comments on commit 11ad034

Please sign in to comment.