Dockers

Docker – How to Install WordPress & MySQL using Docker

WordPress or PHP developers may find it difficult to do a fresh installation of WordPress and MySQL in a quick manner. This is where Docker comes to rescue. With Docker, one can quickly commission (or setup or install) and de-commission WordPress & MySQL development environment in no time.

In this post, you will learn about some of the following:

  • Pre-requisites – Docker Installation
  • How to install WordPress and MySQL as container apps using Docker
  • Access wordpress in browser
  • Access wordpress installation within Docker container
  • Access MySQL installation within Docker container

Pre-requisites – Docker Installation

Before getting started with WordPress/MySQL , first and foremost, Docker needs to be installed. Briefly speaking, Docker platform is the container platform to build, secure and manage the widest array of applications from development to production both on premises and in the cloud. The greater details can be found on this page, What is Docker?

Docker platform comes in two different editions: community and enterprise edition.

For development purpose, community edition would suffice. Details on how to install Docker can be found on this page, Install Docker.

Install WordPress & MySQL as Docker Container Apps

The following is the code for docker-compose file.  Save the code in a file, say, wordpress-installation.yml

version: "2.0"

services:

  wordpress:
    image: wordpress
    restart: always
    ports:
      - 8090:80
    environment:
      WORDPRESS_DB_PASSWORD: root 

  mysql:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: root

In above docker compose file, pay attention to some of the following:

  • There are two containers which run as a result of executing docker compose file. They are wordpress and MySQL containers.
  • WordPress containers run using (on top of) wordpress image.
  • In WordPress container, wordpress starts at port 80. It is accessible from outside in a browser in 8090. (http://192.168.99.100:8090/)
  • MySQL container runs using (on top of) MySQL image (version 5.7).
  • MySQL is installed with password as “root”

Execute the following command for installing wordpress and MySQL:

docker-compose -f wordpress-installation.yml up

Access WordPress in Browser

Open a browser and access wordpress installation by typing URL as http://localhost:8090 or http://192.168.99.100:8090/. You would see the first page such as following:

Figure 1. WordPress Installation from Browser

Access WordPress installation within Docker container

Execute the following command to view all the containers:

 
docker ps

The wordpress container may be identified with name such as “documents_wordpress_1”. Access the wordpress with command such as following:

 
docker exec -ti documents_wordpress_1 /bin/bash

You would be taken to the folder “/var/www/html”. Execute command such as “ls -l” to check all the files.

Access MySQL installation within Docker container

Execute the following command to view all the containers:

 
docker ps

The wordpress container may be identified with name such as “documents_mysql_1”. Access the wordpress with command such as following:

 
docker exec -ti documents_mysql_1 /bin/bash

Execute following command to access the MySQL database:

 
mysql -u root -proot
show databases;
use wordpress;

Further Reading/References

Summary

In this post, you learned about installing WordPress and MySQL using Docker. Did you find this article useful? Do you have any questions or suggestions about this article in relation to installing WordPress and MySQL using Docker? Leave a comment and ask your questions and I shall do my best to address your queries.

 

 

Ajitesh Kumar

I have been recently working in the area of Data analytics including Data Science and Machine Learning / Deep Learning. I am also passionate about different technologies including programming languages such as Java/JEE, Javascript, Python, R, Julia, etc, and technologies such as Blockchain, mobile computing, cloud-native technologies, application security, cloud computing platforms, big data, etc. I would love to connect with you on Linkedin. Check out my latest book titled as First Principles Thinking: Building winning products using first principles thinking.

Share
Published by
Ajitesh Kumar

Recent Posts

Agentic Reasoning Design Patterns in AI: Examples

In recent years, artificial intelligence (AI) has evolved to include more sophisticated and capable agents,…

3 weeks ago

LLMs for Adaptive Learning & Personalized Education

Adaptive learning helps in tailoring learning experiences to fit the unique needs of each student.…

4 weeks ago

Sparse Mixture of Experts (MoE) Models: Examples

With the increasing demand for more powerful machine learning (ML) systems that can handle diverse…

4 weeks ago

Anxiety Disorder Detection & Machine Learning Techniques

Anxiety is a common mental health condition that affects millions of people around the world.…

1 month ago

Confounder Features & Machine Learning Models: Examples

In machine learning, confounder features or variables can significantly affect the accuracy and validity of…

1 month ago

Credit Card Fraud Detection & Machine Learning

Last updated: 26 Sept, 2024 Credit card fraud detection is a major concern for credit…

1 month ago