How to Install WordPress on Docker using Portainer

In our homelab series, we already saw how we can create a docker host. We also saw how we can install the portainer in the docker host. Now we have our home server ready. Now let’s install WordPress in our docker host.

What is WordPress?

For people who are not aware of WordPress. let’s discuss WordPress. It is a free and open-source content management system written in PHP and paired with a MySQL or MariaDB database. If you want to develop a website WordPress is a go-to option for you. There are more than 70% of the website on the internet are built upon WordPress. Due to its ease of use, lots of people like to use WordPress.

Prerequisites

To start with the article you need to follow the below article first. Using this we can install our WordPress website.

How to install WordPress on docker using Portainer

So to install WordPress let’s first discuss the important element of WordPress. That it needs to work. We need two containers to run the WordPress.

  • MySQL
  • WordPress

In the MySQL container, all the important databases will store. in the WordPress container, all the files that are required for WordPress will store.

Let’s see how we can install WordPress. Will install the WordPress using the docker-compose method. We also use the stack to deploy the website.

Stack is like a template that you create in portainer. We need to follow the below steps to host the website.

  • Open the portainer web UI and click on stacks from the left-hand panel.
  • There you will see a button with the name Add stack. Click on that.
  • First you need to mention the name of the stack. here will name WordPress(make it small). Now click on web editor and paste the below code.
version: '3.1'

services:

  wordpress:
    image: wordpress
    restart: always
    ports:
      - 8080:80
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: exampleuser
      WORDPRESS_DB_PASSWORD: examplepass
      WORDPRESS_DB_NAME: exampledb
    volumes:
      - wordpress:/var/www/html

  db:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_DATABASE: exampledb
      MYSQL_USER: exampleuser
      MYSQL_PASSWORD: examplepass
      MYSQL_RANDOM_ROOT_PASSWORD: '1'
    volumes:
      - db:/var/lib/mysql

volumes:
  wordpress:
  db:
  • Now click on the deployed stack.
screely 1655921413430
Portainer Stack
  • It will create two containers that you can see from the container tab from the left-hand menu.
screely 1655921454602
Portainer Container

Accessing the website

From the previous steps we know, How we can create the WordPress container. Now we need to access that. For that you need to open the below link:

Server_ip:8080

The default WordPress setup screen will pop up in front of you.

screely 1655921520928
WordPress Setup Page

So using this small article you can host a WordPress site in your docker host.

Leave a Reply

Your email address will not be published. Required fields are marked *