Hostomy Blog

How to Install WordPress on Ubuntu Using Docker

Dec 04, 2024

By Rahul Mukati

Rahul Mukati
How to Install WordPress on Ubuntu Using Docker

WordPress powers millions of websites worldwide, thanks to its flexibility and ease of use. Pairing it with Docker simplifies deployment, making it a breeze to set up and maintain. In this guide, we’ll walk you through installing WordPress on an Ubuntu machine using Docker.

Need a reliable server? Get started with a Hostomy Cloud Server

Why Use Docker for WordPress?

Docker enables you to run WordPress and its dependencies, such as MySQL, in isolated containers. This means:

  • Ease of deployment: Quickly set up a consistent environment.
  • Portability: Move your containers between systems effortlessly.
  • Simplified management: Manage WordPress and MySQL independently.

Pre-requisites

Before starting, ensure you have:

  1. A Linux server running Ubuntu (Ubuntu 24.04 is recommended).
  2. Docker and Docker Compose installed. Check out our Docker installation guide.
  3. Sudo privileges on your system.

Step 1: Set Up Your Server

If you don’t already have a server, choose a reliable one from Hostomy. Once your server is ready, log in via SSH:

ssh username@your_server_ip  

Step 2: Create a Docker Compose File

Docker Compose simplifies managing multiple containers. Create a directory for your project and navigate to it:

mkdir wordpress-docker  
cd wordpress-docker  

Then, create a docker-compose.yml file:

nano docker-compose.yml  

Add the following content:

version: '3.3'  
services:  
  wordpress:  
    image: wordpress:latest  
    container_name: wordpress  
    ports:  
      - "8080:80"  
    environment:  
      WORDPRESS_DB_HOST: db  
      WORDPRESS_DB_USER: wordpress  
      WORDPRESS_DB_PASSWORD: wordpress_password  
      WORDPRESS_DB_NAME: wordpress  
    volumes:  
      - wordpress_data:/var/www/html  
  db:  
    image: mysql:8.0
    container_name: wordpress_db  
    environment:  
      MYSQL_ROOT_PASSWORD: root_password  
      MYSQL_DATABASE: wordpress  
      MYSQL_USER: wordpress  
      MYSQL_PASSWORD: wordpress_password  
    volumes:  
      - db_data:/var/lib/mysql  
volumes:  
  wordpress_data:  
  db_data:  

This configuration sets up two services:

  • WordPress: The application itself.
  • MySQL: A database for WordPress.

Step 3: Start the Containers

Run the following command to start the WordPress and MySQL containers:

docker-compose up -d  

This will download the required images and start the containers in detached mode.

Step 4: Access Your WordPress Site

Once the containers are running, open a browser and visit:

http://your_server_ip:8080  

You’ll see the WordPress setup wizard.

Step 5: Complete WordPress Setup

  1. Choose a language.
  2. Enter the database details:
  • Database Name: wordpress
  • Username: wordpress
  • Password: wordpress_password
  • Database Host: db
  1. Click Submit, then run the installation.
  2. Enter your site details (e.g., site name, admin username, and password).

Congratulations! Your WordPress site is now live.

Managing Your WordPress Containers

View Running Containers

docker ps  

Stop Containers

docker-compose down  

Restart Containers

docker-compose up -d  

Next Steps

With WordPress running, you can:

  1. Install themes and plugins to customize your site.
  2. Enable HTTPS using a reverse proxy like Nginx and a Let's Encrypt SSL certificate.
  3. Regularly back up your database and WordPress files for security.

Why Hostomy for Your Cloud Hosting?

For a seamless WordPress experience, choose a Hostomy Cloud Server. Our servers are optimized for speed, reliability, and scalability, making them ideal for Docker deployments.

Get started with Dockerized WordPress today and unleash the potential of your website! 🚀