dockerise
scan using snyk
both dockerfile
// backend
# ---- Base image ----
FROM python:3.11-slim AS base
# Set working directory
WORKDIR /app
# Install system dependencies (psycopg2 needs them)
RUN apt-get update && apt-get install -y \
gcc libpq-dev curl \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements first (for caching layers)
COPY requirements.txt .
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Copy app source
COPY app ./app
# Expose port
EXPOSE 8000
# Start FastAPI with uvicorn
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
// frontend
# ---- Build Stage ----
FROM node:20 AS build
WORKDIR /app
# Install dependencies
COPY package.json package-lock.json* ./
RUN npm install
# Copy rest of source
COPY . .
# Build production files
RUN npm run build
# ---- Serve Stage ----
FROM nginx:1.25-alpine
# Copy build output to Nginx html dir
COPY --from=build /app/dist /usr/share/nginx/html
# Copy custom Nginx config (optional)
# e.g. if you want to handle SPA routes
# COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
compose for local testing
version: "3.9"
services:
db:
image: postgres:15
container_name: postgres_db
restart: always
environment:
POSTGRES_USER: daybuddy_user
POSTGRES_PASSWORD: change_me_strong_password
POSTGRES_DB: daybuddy
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
backend:
build: ./backend
container_name: fastapi_backend
restart: always
environment:
DB_USER: daybuddy_user
DB_PASS: change_me_strong_password
DB_HOST: db
DB_PORT: 5432
DB_NAME: daybuddy
ports:
- "8000:8000"
depends_on:
- db
frontend:
build: ./frontend
container_name: react_frontend
restart: always
ports:
- "3000:80" # 3000 on host → 80 inside container (nginx)
volumes:
postgres_data:
Last updated