The Easy Guide To Install WordPress With Docker

Docker is a software that enables the use and creation of Containers. To deploy WordPress Containers can be used. Here, we will discuss the benefits of using Docker and how you can install WordPress with Docker.   

Let’s get started.

Make your WordPress site’s Load Blazing Fast Just by moving to Nestify. Migrate your WooCommerce Store or WordPress Website NOW.

The Benefits of Using Docker

To set up WordPress, you need a proper stack; it may be LAMP (Linux, Apache, MySQL, PHP) or LEMP (Linux, Nginx, MySQL, PHP). Installing all these components can be time-consuming, and you may not have the flexibility to play with your code. This is where Docker comes in.

Docker uses containers to create, deploy, and run applications. Each box supports a self-contained environment where you can set up your stack, libraries, and dependencies. Different containers can have different backgrounds. Thus, you can install WordPress with Apache in one box and Nginx on another. You can turn on or turn off a container if you wish. With tools like Docker Compose, you can run multi-container applications.

You just need 2 containers and a Docker compose file to have your own WordPress installation.

How to install WordPress with Docker

You need to have Docker, Docker-Compose and a docker-compose.yml file on your server. Follow these steps to install WordPress with Docker:

Step 1: Install Docker Using the Official Repository

If you are installing Docker for the first time, you need to follow all these steps to set up the Docker Repository. After that, you will be able to update Docker from the repository.

If you have already set up the Docker repository, then you just need to perform step no. 5 and 6 to install Docker.

  1. Update the apt package index:
 $ sudo apt-get update 

2. Install packages to allow apt to use a repository over HTTPS:

$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common

3. Add Docker’s official GPG Key:

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

4. Use the following command to set up the stable repository:

$ sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

5. Update the apt package index.

$ sudo apt-get update

6. Install the latest version of Docker CE and containers

 $ sudo apt-get install docker-ce docker-ce-cli containerd.io

Step 3: Install Docker-Compose

This is how you can install Docker-Compose:

  1. Run this command to download the current stable release of Docker Compose:
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

2. Apply executable permissions to the binary:

 sudo chmod +x /usr/local/bin/docker-compose

Step 3: Create a docker-compose.yml File

To install WordPress we need two containers; one for WordPress and other for Database. These two can be set up using a single docker-compose.yml file that contains the following:

 version: '3'

services:
   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     volumes:
       - wp_data:/var/www/html
     ports:
       - "80:80"
     restart_policy:
      condition: on-failure
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: my_wordpress_db_password

   db:
     image: mariadb
     volumes:
       - db_data:/var/lib/mysql
     restart_policy:
      condition: on-failure
     environment:
       MYSQL_ROOT_PASSWORD: my_db_root_password
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: my_wordpress_db_password
volumes:
    wp_data:
    db_data:

Step 4: Get Docker-Compose ready

  1. Move the docker-compose.yml file to a file location that you can conveniently access.

An example would be ~wordpress/docker-compose.yml

2. From the directory where you just put the docker-compose.yml file, run the following command:

docker-compose up -d

Step 5: Get started with WordPress

Your WordPress is now installed and ready to be set up. You can visit the setup page by visiting the IP address of your server.


So this is how you can install WordPress with Docker. You can always refer to Docker’s official documentation for prerequisites. If you have any queries do leave us a comment.

Make your WordPress site’s Load Blazing Fast Just by moving to Nestify. Migrate your WooCommerce Store or WordPress Website NOW.

Related Post

Leave a Reply