Skip to content

📥 Sample document: How to Run a Project Using Docker Compose

Sample document illustrating the deployment of a project using Docker Compose

Introduction

Docker Compose is a tool that facilitates the management of applications composed of multiple containers. It allows for the configuration and running of complex environments defined in YAML files. Its use is particularly beneficial in the process of creating, testing, and deploying microservices.

Prerequisites

To run a project using Docker Compose, we need:

  • Docker installed (version 1.13.0 or newer)
  • Docker Compose installed (version 1.10.0 or newer)
  • A docker-compose.yml file defining the services

Configuration of the docker-compose.yml File

The docker-compose.yml file is the heart of the configuration. An example content of the file for a simple project might look as follows:

version: '3'
services:
  web:
    image: nginx:latest
    ports:
      - "80:80"
  app:
    image: myapp:latest
    depends_on:
      - db
  db:
    image: postgres:alpine
    environment:
      POSTGRES_DB: exampledb
      POSTGRES_USER: exampleuser
      POSTGRES_PASSWORD: examplepass

Explanation of Components:

  • version: Specifies the version of the configuration file.
  • services: Defines a list of all services (containers) to be run.
    • web: Nginx server service with port 80 exposed.
    • app: Application dependent on the database.
    • db: PostgreSQL database service with configuration values passed through environment variables.

Running the Project

To run the configured environment, execute the following command in the directory containing the docker-compose.yml file:

docker-compose up

This works interactively, fetching the required images, building containers, and running them. For non-interactive mode, use the -d flag:

docker-compose up -d

Managing the Project

  • To stop all running services, use:
docker-compose down
  • To rebuild images if the Dockerfile files have changed:
docker-compose build

Debugging and Logging

Docker Compose also allows monitoring logs:

docker-compose logs -f

Verifying Running Services

Check the status of running services by executing:

docker-compose ps

Summary

Docker Compose greatly simplifies the deployment process of applications requiring multiple environments. By centralizing the configuration in a single YAML file, it allows for easy launching, stopping, and managing of containers. The efficiency and flexibility of this tool make it invaluable in handling complex application architectures.

This document is only a demonstration of deployment methods using Docker Compose.