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.

<code>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
</code>

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:

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

To stop and remove the containers use:

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

Docker Compose for Nginx with Persistent Storage

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

Start it with:

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

Verify with

curl localhost

which returns

hello

.

DockernginxYAMLContainer 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

login 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.