Docker Compose Tutorial: Installing, Configuring, and Running a WordPress Application
This guide explains how to install Docker Compose on Ubuntu, create a docker‑compose.yml file to define WordPress and MySQL services, configure volumes, environment variables, and networking, and then start, verify, and manage the containers, providing a complete end‑to‑end example of Docker Compose usage.
Docker Compose allows managing multi‑container Docker applications via a single configuration file, eliminating the need for shell scripts.
System environment: Ubuntu 17.04 x64, Docker CE 17.12.0‑ce, Docker Compose 1.18.0.
Installation: download the latest binary with curl and apply executable permission:
curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose --versionUninstall by removing the binary: rm /usr/local/bin/docker-compose Example: a WordPress site with a MySQL database. Create project directory and docker‑compose.yml:
mkdir my_wordpress
cd my_wordpress
cat > docker-compose.yml <<EOF
version: '3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
volumes:
db_data:
EOFStart the services in detached mode: docker-compose up -d Verify that the containers are pulling images and running, then access the site at http://localhost:8000.
Additional commands to inspect containers, images, and to enter the MySQL container for data verification are provided, demonstrating volume mounting and persistence.
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.
Architect's Tech Stack
Java backend, microservices, distributed systems, containerized programming, and more.
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.
