Project

General

Profile

๐Ÿณ Docker

This page documents containerized application deployment using Docker and Ansible in the homelab. It covers architecture, deployment workflow, version pinning, and integration with external resources like PostgreSQL or NFS.

Think of this as a generic framework for all containerized services in the homelab.


๐Ÿ— Architecture Overview

                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                  โ”‚ Host / Docker Environment โ”‚
                  โ”‚                           โ”‚
                  โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
                  โ”‚ โ”‚ App Container 1       โ”‚ โ”‚
                  โ”‚ โ”‚ - Pinned Image        โ”‚ โ”‚
                  โ”‚ โ”‚ - Config & Backup     โ”‚ โ”‚
                  โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
                  โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
                  โ”‚ โ”‚ App Container 2       โ”‚ โ”‚
                  โ”‚ โ”‚ - Pinned Image        โ”‚ โ”‚
                  โ”‚ โ”‚ - Config & Backup     โ”‚ โ”‚
                  โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
                  โ”‚                           โ”‚
                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ฒโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                โ”‚ Access
                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                  โ”‚ Users / Clients           โ”‚
                  โ”‚ Web Browser / API         โ”‚
                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ฒโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                โ”‚ Database or Shared Storage
                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                  โ”‚ External Services         โ”‚
                  โ”‚ - PostgreSQL              โ”‚
                  โ”‚ - NFS / Network Storage   โ”‚
                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Key Notes:

  • Each app runs in an isolated container
  • Configs and backups stored in persistent volumes
  • Containers can connect to external resources like PostgreSQL or NFS

Architecture & Deployment Approach

  • Docker-Compose Templates: Use a template docker-compose.yml as the primary definition for container services, volumes, ports, and environment variables.

  • Application Configuration Files: Applications may provide their own configuration files (e.g., config.xml, app.cfg) that should be mounted into the container.

  • Volumes & Backups: Persist data via host-mounted volumes or NFS shares for configuration and data storage.

  • Service Lifecycle Tasks: Typical Ansible tasks include:

    1. Creating configuration directories
    2. Copying template files
    3. Starting, stopping, and updating containers
    4. Cleaning up unused images and networks

Example Directory Layout:

/config/
   โ”œโ”€โ”€ app1/
   โ”‚    โ”œโ”€โ”€ docker-compose.yml
   โ”‚    โ””โ”€โ”€ app1.cfg
   โ””โ”€โ”€ app2/
        โ”œโ”€โ”€ docker-compose.yml
        โ””โ”€โ”€ app2.cfg
/nfs/backups/
   โ”œโ”€โ”€ app1/
   โ””โ”€โ”€ app2/

โš™๏ธ Docker Deployment

1. Stop & remove existing container

docker stop <container>
docker rm <container>
docker network prune -f

2. Ensure persistent directories exist

mkdir -p /config/appname
mkdir -p /nfs/backups/appname
chown <user>:<group> /config/appname

3. Deploy templated configuration files

  • docker-compose.yml
  • App-specific configuration (e.g., config.xml, sabnzbd.ini)

4. Prune unused Docker images (optional)

docker image prune -f

5. Pull pinned Docker image

docker-compose -f /config/appname/docker-compose.yml pull

6. Start container

docker-compose -f /config/appname/docker-compose.yml up -d

The Docker Deployment Example Commands vs Ansible Tasks page provides a side-by-side equivalence between manual Docker deployment commands and the automated Ansible tasks.


๐Ÿ”’ Version Pinning & Best Practices

  • Always pin Docker images to a specific version:
app_setup_version: "1.2.3"
app_setup_docker_image_name: "appname:{{ app_setup_version }}"
  • Avoid latest for reproducibility
  • Use templated Docker Compose files
  • Keep config & data volumes separate
  • Store logs/backups on persistent network storage

๐ŸŒ Integrating External Resources

  • Databases: e.g., Radarr, Sonarr, Lidarr use external PostgreSQL
app_setup_pg_host: "{{ global_ip_addresses[groups['pgdb'][0]] }}"
app_setup_pg_port: 5432
  • Network Storage: Configs, downloads, backups mounted from NFS or Ceph
  • Containers connect via environment variables and mounted volumes

๐ŸŽฏ Key Features

  • Fully automated container deployment via Ansible
  • Persistent configuration & backup volumes
  • Pinned Docker images for reproducibility
  • Template-driven, scalable deployments
  • Integration with external databases and network storage
  • Reusable workflow for all homelab apps

๐Ÿ“š Related Pages