Step-by-Step Guide: How to Install WordPress Using Docker on Ubuntu
Introduction
Setting up WordPress on Ubuntu using Docker can greatly simplify development and provide a consistent environment for testing and deployment. This guide will walk you through all the necessary steps to install WordPress using Docker on an Ubuntu system.
Prerequisites for Ubuntu
Before starting, make sure your Ubuntu system meets the following requirements:
- Ubuntu 20.04 or later
- Docker
- Docker Compose
- At least 4 GB of RAM and 10 GB of disk space
You should also ensure that your system is up to date by running:
sudo apt-get update sudo apt-get upgrade
Step 1: Install Docker on Ubuntu
-
Install Docker: To install Docker, run the following command:
sudo apt-get install docker.io
-
Start Docker and enable it on boot:
sudo systemctl start docker sudo systemctl enable docker
-
Verify Docker installation: Confirm that Docker is installed by checking its version:
docker --version
Step 2: Install Docker Compose on Ubuntu
sudo apt-get install docker-compose
docker-compose --version
Step 3: Create a Docker Compose File for WordPress
mkdir wordpress-docker
cd wordpress-docker
nano docker-compose.yml
docker-compose.yml
file with
the following content:
version: '3.8'
services:
wordpress:
image: wordpress:latest
ports:
- "8000:80"
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: user
WORDPRESS_DB_PASSWORD: password
WORDPRESS_DB_NAME: wordpress
volumes:
- ./wp-data:/var/www/html
db:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: wordpress
MYSQL_USER: user
MYSQL_PASSWORD: password
volumes:
- ./db-data:/var/lib/mysql
Step 4: Start WordPress Using Docker Compose
-
Run Docker Compose: Start the containers by running:
docker-compose up -d
-
Access WordPress in Your Browser: Open a web browser and go to
http://localhost:8000
. This will take you to the WordPress setup screen.
Step 5: Configure WordPress
Once the containers are up, you will be prompted to configure WordPress.
Choose your language, set up your admin credentials, and connect to the
MySQL database using the values from the
docker-compose.yml
file.
Managing Docker Containers on Ubuntu
-
Start containers:
docker-compose start
-
Stop containers:
docker-compose stop
-
Check container status:
docker ps
Backup and Restore WordPress on Ubuntu
-
Backup:
Archive the
wp-data
anddb-data
directories.
- Restore: Copy the directories back into place and run Docker Compose again.