Cloud Native 4 min read

Master Docker Compose: Install, Write YAML, and Deploy WordPress & Nginx

This guide walks you through installing Docker Compose, crafting correct YAML files for WordPress and Nginx services, and using Docker Compose commands to launch, manage, and remove containers, highlighting key syntax rules such as quoting strings and avoiding tabs.

Raymond Ops
Raymond Ops
Raymond Ops
Master Docker Compose: Install, Write YAML, and Deploy WordPress & Nginx

Docker Compose Installation

If you have already set up Harbor, you can skip this step.

Docker Compose File Format

Docker Compose uses YAML, which relies on indentation; tabs are not allowed and the file is case‑sensitive.

services:
  blog:
    image: wordpress
    links:
      - db:db
    ports:
      - "80:80"
    environment:
      - WORDPRESS_DB_HOST=db
      - WORDPRESS_DB_USER=root
      - "WORDPRESS_DB_PASSWORD=123"
      - WORDPRESS_DB_NAME=wordpress
  db:
    image: mysql
    environment:
      - "MYSQL_ROOT_PASSWORD=123"
      - MYSQL_DATABASE=wordpress

Strings such as ports must be quoted; numeric values also need quotes to be interpreted correctly.

Running Docker Compose

Save the file as wordpress.yml and start the containers:

# docker compose -f wordpress.yml up -d
[+] Running 3/3
✔ Network compose_default   Created
✔ Container compose-db-1   Started
✔ Container compose-blog-1 Started

To stop and remove the containers use:

# docker compose -f wordpress.yml down
[+] Running 3/3
✔ Container compose-blog-1  Removed
✔ Container compose-db-1     Removed
✔ Network compose_default   Removed

Docker Compose for Nginx with Persistent Storage

services:
  web01:
    image: nginx
    ports:
      - "80:80"
    volumes:
      - "/html:/usr/share/nginx/html"

Start it with:

# docker compose -f nginx.yml up -d
[+] Running 2/2
✔ Network compose_default Created
✔ Container compose-web01-1 Started

Verify with curl localhost which returns hello.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DockerYAMLcontainer orchestrationWordPressDocker Compose
Raymond Ops
Written by

Raymond Ops

Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.