Awesome Compose

repository·master·Indexed 13 days ago

https://github.com/docker/awesome-compose

A curated repository of Docker Compose samples providing starting points for integrating multiple services—including databases, proxies, backends, and frontends—into containerized applications. Includes deployment guides for Angular, PHP with Apache2, ASP.NET with MS SQL Server, Django, ELK stack (Elasticsearch, Logstash, Kibana), FastAPI, and Flask with Redis.

Tokens
53.6K
Snippets
210
Records
248
Agent score
97%

What's inside Awesome Compose

  1. Overview of Awesome Compose samples

    master

    Awesome Compose is a curated collection of Docker Compose samples designed to help developers integrate different services using Compose files.

    Warning: These samples are intended for local development environments (project setups, tinkering with software stacks, etc.) and must not be deployed in production environments.

  2. Configure MongoDB persistent storage in Compose

    master

    To ensure MongoDB data is not lost when containers are removed, the mongo service uses volume mounting. The configuration maps a host directory to the container's internal database directory (/data/db).

    To persist changes to your local machine, ensure you have created a directory in your project root to act as the mount point, and update the compose.yaml to point to it.

  3. Configure the NODE_PORT build argument

    master

    The backend Dockerfile uses a build argument named NODE_PORT. This allows you to define the application's port dynamically via your docker-compose.yaml file or during a manual docker build.

    In the Dockerfile, this argument is used in two places:

    1. To log the value: RUN echo "Argument port is : $NODE_PORT"
    2. To expose the port: EXPOSE ${NODE_PORT}

    Ensure that the port passed as an argument matches the port your application is configured to bind to (e.g., via an environment variable or .env file).

  4. Best practices for Node.js Dockerfiles

    master

    This project implements several production-minded and development-optimized patterns for Node.js Docker images:

    Development Optimization

    • Avoid host dependencies: node_modules are installed outside the app root in the container to prevent bind-mount conflicts with local host source code.
    • Fast builds: The Dockerfile copies package.json and runs npm install before copying the rest of the source code. This leverages Docker layer caching to speed up rebuilds.
    • Debugging: The setup enables the inspect port 9229 by default, allowing host-based debugging (e.g., Chrome DevTools or VS Code) via nodemon --inspect.

    Production Readiness

    • Healthchecks: Uses the Dockerfile HEALTHCHECK instruction with a /healthz route to allow Docker to monitor container health.
    • Environment Isolation: Uses NODE_ENV=production by default in the Dockerfile. Dev dependencies are only installed when NODE_ENV is overridden to development (via docker-compose).
    • Graceful Shutdowns: Uses node index.js as the entrypoint instead of npm. This ensures that SIGTERM and SIGINT signals are passed directly to the Node process, allowing for proper graceful exits.
    • Deployment: For Docker Swarm deployments, use the provided docker-stack.yml instead of compose.yaml.
  5. Understand the NGINX -> WSGI -> Flask architecture

    master

    The application follows a specific traffic flow: Client -> NGINX -> WSGI -> Flask.

    • NGINX: Acts as a reverse proxy. It can be used for caching responses, acting as a load balancer between multiple Flask backends, or integrating a Web Application Firewall (WAF).
    • WSGI (Web Server Gateway Interface): The interface between the proxy and the backend. In this sample, Gunicorn is used as the WSGI server to handle scalable request processing.
    • Flask: The Python web framework that serves as the backend logic.
  6. Use an entrypoint script to handle Rails server.pid

    master

    Rails often fails to restart if a server.pid file from a previous session still exists in the tmp/pids/ directory. To prevent this, use an entrypoint.sh script that removes the file before executing the main command.

    #!/bin/bash
    set -e
    
    # Remove a potentially pre-existing server.pid for Rails.
    rm -f /myapp/tmp/pids/server.pid
    
    # Then exec the container's main process (what's set as CMD in the Dockerfile).
    exec "$@"
  7. Key concepts covered by Compose samples

    master

    The samples in this repository are designed to teach the following core Docker Compose concepts:

    • Service Definition: How to define services based on Docker images using docker-compose.yml files.
    • Compose vs. Dockerfiles: Understanding the relationship between the orchestration layer (docker-compose.yml) and the image building layer (Dockerfiles).
    • Service Communication: Learning how to make calls to your application services as defined within Compose files.
  8. Understand the React-Express-MongoDB service architecture

    master

    The application is defined in a compose.yaml file with three primary services:

    • frontend: A React application built from the frontend directory. It maps host port 3000 to container port 3000.
    • server: A Node.js/Express backend. It uses a Dockerfile in the server directory and accepts a build argument NODE_PORT. It depends on the mongo service and maps host port 3000 to container port 3000.
    • mongo: A MongoDB database service. Instead of a local Dockerfile, it pulls the mongo:4.2.0 image directly from DockerHub. It uses a volume mount to ensure persistent storage by mapping a local directory to the container's /data/db path.

    Note on Port Conflicts: In this specific configuration, both frontend and server are mapped to host port 3000. Ensure your host environment can handle this or modify the compose.yaml to use different host ports.

  9. Quickstart guides for Django, Rails, and WordPress

    master

    The repository provides specific quickstart guides for common application stacks using Docker Compose:

    • Django & PostgreSQL: A guide to setting up and running a simple Django application with a PostgreSQL database.
    • Rails & PostgreSQL: A guide to setting up and running a Ruby on Rails application with a PostgreSQL database.
    • WordPress: A guide to running WordPress in an isolated environment using Docker containers.