How To Install WordPress In Docker Container

How To Install WordPress In Docker Container

June 18, 2020 / Nirav Shah

Install WordPress In Docker Container: Complete Guide

a.What is wordpress ?

WordPress (WordPress.org) is a free and open-source content management system (CMS) written in PHP and paired with a MySQL or MariaDB database. Features include a plugin architecture and a template system, referred to within WordPress as Themes. WordPress was originally created as a blog-publishing system but has evolved to support other types of web content including more traditional mailing lists and forums, media galleries, membership sites, learning management systems (LMS) and online stores. WordPress is used by more than 60 million websites including 33.6% of the top 10 million websites as of April 2019 WordPress is one of the most popular content management system solutions in use WordPress has also been used for other application domains such as pervasive display systems (PDS)

b.What is Docker ?

Docker is a set of platform as a service (PaaS) products that uses OS-level virtualization to deliver software in packages called containers Containers are isolated from one another and bundle their own software, libraries and configuration files; they can communicate with each other through well-defined channels All containers are run by a single operating system kernel and therefore use fewer resources than virtual machines.

c.Steps to launch wordpress in Docker Container

Step 1

Launch a new server using AWS

Step 2

Login to your server

$ ssh -i key-pair.pem ubuntu@ip

install-Wordpress-docker

Step 3

Update the server to get the latest version of packages installed in the server

$ sudo apt update && sudo apt upgrade -y

install-Wordpress-docker

Install Docker

Step 4

Installing Docker itself is already easy.

$ sudo apt install docker.io

install-Wordpress-docker

MariaDB in a container

Step 5

Before installing WordPress with Docker you will need to have somewhere to store the data. MariaDB is a community-developed relational database management system and a drop-in replacement for MySQL. It is officially available on Docker and provides easy instructions with up to date images.
Start off by making a new directory where you wish to store the files for WordPress and MariaDB for example in your home directory.

$ mkdir wordpress

install-Wordpress-docker

$ cd wordpress

install-Wordpress-docker

Step 6

Downloading and installing a new MariaDB container can all be performed with a single command. Before jumping in check the required parameters.
MariaDB Environment variables, these are marked in the Docker command with -e:

  • -e MYSQL_ROOT_PASSWORD= Set your own password here.
  • -e MYSQL_DATABASE= Creates and names a new database e.g. wordpress.
    Docker parameters:
  • –name – Names the container.
  • -v “$PWD/database”:/var/lib/mysql – Creates a data directory linked to the container storage to ensure data persistence.
  • -d – Tells Docker to run the container in daemon.
  • mariadb:latest – Finally defines what to install and which version.
  • Then run the command below while replacing the and with your own.
  • $ sudo docker run -e MYSQL_ROOT_PASSWORD= -e MYSQL_DATABASE=wordpress –name -v “$PWD/database”:/var/lib/mysql -d mariadb:latest

install-Wordpress-docker

Step 7

You can confirm that the MariaDB container is running by using the following command:

$ sudo docker ps

install-Wordpress-docker

Step 8

Check the status for your MariaDB install, it should show “Up” and the time it has been running like in the example output below.

install-Wordpress-docker

Other useful commands for working with containers are ‘start’, ‘stop’ and ‘remove’.

$ sudo docker start 
$ sudo docker stop 
$ sudo docker rm 

You can find out more about available commands and options to specific commands.

$ sudo docker --help
$ sudo  --help

WordPress with Docker

Step 9

Applications in containers run isolated from one another in the userspace of the host operating system sharing the kernel with other containers. This reduces the overhead required to run packaged software while also enabling the containers to run on any kind of infrastructure. To allow applications within different containers to work with one another Docker supports container linking.

WordPress is also made officially available on Docker Hub, pull the image using the command below. When the version to download is not specified Docker will fetch the latest available.

$ sudo docker pull wordpress

install-Wordpress-docker

Step 10

WordPress container also takes environment variables and Docker parameters:

  • -e WORDPRESS_DB_PASSWORD= Set the same database password here.
  • –name – Gives the container a name.
  • –link :mysql – Links the WordPress container with the MariaDB container so that the applications can interact.
  • -p 80:80 – Tells Docker to pass connections from your server’s HTTP port to the container’s internal port 80.
  • -v “$PWD/html”:/var/www/html – Sets the WordPress files accessible from outside the container. The volume files will remain even if the container was removed.
  • -d – Makes the container run on background
  • wordpress – Tells Docker what to install. Uses the package downloaded earlier with the docker pull wordpress -command.
  • Run the command below while replacing the and as you did for the MariaDB container.
  • docker run -e WORDPRESS_DB_PASSWORD= –name –link :mysql -p 80:80 -v “$PWD/html”:/var/www/html -d wordpress

install-Wordpress-docker

Step 11

You can confirm that the WordPress container is running by using the following command:

$ sudo docker ps

install-Wordpress-docker

Step 12

Check the status for your WordPress install, it should show “Up” and the time it has been running like in the example output below.

install-Wordpress-docker

Step 13

Then open your server’s domain name or IP address in a web browser to test the installation. You should be redirected to the initial WordPress setup page at http:///wp-admin/install.php. Go through the setup wizard and you are done.

initial WordPress setup page

Also Read:

1. Step by Step Guide to Install WordPress on AWS for free

2. How to Migrate WordPress site to AWS with Cloudfront

FAQs:

1.Is Docker good for web server?

2.Can I run WordPress in a container?

Talk to AWS Certified Consultant

    Spread Love By Sharing:

    Let Us Talk About Your AWS Development Requirements

    Have queries about your AWS project ideas and concepts? Please drop in your project details to discuss with our AWS experts, professionals and consultants.

    • Swift Hiring and Onboarding
    • Experienced and Trained AWS Team
    • Quality Consulting and Programming
    Let’s Connect and Discuss Your Project