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 \

3. Add Docker’s official GPG Key:

$ curl -fsSL | sudo apt-key add -

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

$ sudo add-apt-repository \
   "deb [arch=amd64] \
   $(lsb_release -cs) \

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

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 "$(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'

       - db
     image: wordpress:latest
       - wp_data:/var/www/html
       - "80:80"
      condition: on-failure
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: my_wordpress_db_password

     image: mariadb
       - db_data:/var/lib/mysql
      condition: on-failure
       MYSQL_ROOT_PASSWORD: my_db_root_password
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: my_wordpress_db_password

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