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.
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=wordpressStrings 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 StartedTo 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 RemovedDocker 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 StartedVerify with curl localhost which returns hello.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Raymond Ops
Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
