Phase 3 — Deploy & Use · Step 11 of 14

COMPOSE — Define Apps with docker-compose.yml

Docker Compose lets you define an entire multi-service application in a single YAML file — images, ports, environment variables, volumes and networks all in one place.

Why docker-compose?

Instead of running five docker run commands with long flag lists, you describe your entire application once in a docker-compose.yml file. It improves readability, repeatability and efficiency.

⚠️
Compose vs Stack Deploy: docker-compose up runs everything on the current node only — it does not distribute across the Swarm. To deploy across the full cluster, use docker stack deploy (next step). The deploy: key in the YAML is ignored by docker-compose.
🏗️
This file IS your stack definition. The docker-compose.yml you write here is the exact file you hand to docker stack deploy in the next step. The deploy: block — replicas, placement constraints, restart policies — is only honoured by the Swarm, not by docker-compose up. Write it now; the Swarm will use it.

Sample docker-compose.yml

docker-compose.yml — WordPress + MariaDB + phpMyAdmin
version: "3.6"

services:

  db:
    image: jorgenlarsen/mariadb10.3:rpi
    volumes:
      - db-data:/var/lib/mysql/data
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: root
    ports:
      - '3306:3306'
    networks:
      - overlay
    deploy:
      mode: replicated
      replicas: 1
      endpoint_mode: vip

  wordpress:
    depends_on:
      - db
    image: arm32v7/wordpress
    ports:
      - "8000:80"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: root
    networks:
      - overlay
    deploy:
      mode: replicated
      replicas: 4
      endpoint_mode: vip

  phpmyadmin:
    depends_on:
      - db
    image: arm32v7/phpmyadmin
    restart: always
    ports:
      - "8080:80"
    environment:
      PMA_HOST: db
      MYSQL_ROOT_PASSWORD: root
    networks:
      - overlay
    deploy:
      mode: replicated
      replicas: 4
      endpoint_mode: vip

volumes:
  db-data:

networks:
  overlay:

Run with docker-compose (Single Node)

Start services locally
$ sudo mkdir mariaDB10.3 && cd mariaDB10.3
# Save docker-compose.yml in this directory, then:

$ sudo apt install docker-compose
$ docker-compose up -d

After pulling, you'll see containers for wordpress, db and phpmyadmin start. Use Portainer to inspect the container list and network topology.