Skip to content

🐳 Advanced Docker Guide

This guide provides a deeper look into the Docker configuration for LibreFolio, intended for users who want to customize their deployment.

πŸ“„ docker-compose.yml

The docker-compose.yml file defines the services, networks, and volumes for the application.

πŸ”§ Services

  • backend: The main FastAPI application.
    • πŸ—οΈ build: Specifies the Dockerfile in the project root.
    • πŸ”Œ ports: Maps the host port (defined by ${PORT} in .env) to the container's port 8000.
    • πŸ“‚ volumes:
      • ./backend:/app/backend: Mounts the backend source code for development (allows for hot-reloading).
      • ./frontend/build:/app/frontend/build: Mounts the production frontend build.
      • ./mkdocs_src/site:/app/mkdocs_src/site: Mounts the documentation site.
      • ./logs:/app/logs: Persists log files.
    • 🌍 env_file: Loads environment variables from the .env file.

πŸ’Ύ Volumes

  • libre-folio-data: A named volume used to persist the SQLite database files. This ensures that your data is not lost when you stop or remove the containers.

🌐 Networks

  • libre-folio-net: A custom bridge network to allow services to communicate with each other.

🏭 Production Considerations

For a production deployment, you might consider the following changes:

πŸ”’ 1. Reverse Proxy

It is highly recommended to run LibreFolio behind a reverse proxy like Nginx or Traefik. This allows you to:

  • πŸ” Easily manage SSL/TLS certificates for HTTPS.
  • πŸ–₯️ Serve multiple applications on the same server.
  • πŸ›‘οΈ Add security headers and rate limiting.

πŸ’Ύ 2. Database Backup

Since the database is stored in a Docker volume, you should have a strategy for backing it up. You can use a simple cron job to copy the database file from the volume to a safe location.

Example backup script:

#!/bin/bash
docker cp librefolio_backend_1:/app/backend/data/sqlite/app.db /path/to/backups/app.db-$(date +%F)

🚫 3. Disabling Development Mounts

In a production environment, you may not want to mount the source code directly. You can create a separate docker-compose.prod.yml file that omits the source code volumes and relies solely on the built Docker image.