Deploying a WordPress Website into a Docker Container Using Docker-Compose
WORDPRESS
WordPress is a web content management system. It was created as a tool to publish blogs but has evolved to support publishing other web content, including more traditional websites, mailing lists, Internet forums, media galleries, membership sites, learning management systems, and online stores.
DOCKER
Docker is a set of platform-as-a-service products that use OS-level virtualization to deliver software in packages called containers. The service has both free and premium tiers. The software that hosts the containers is called Docker Engine. It was first released in 2013 and was developed by Docker, Inc.
STEP 1: LAUNCH AND CONFIGURE AN AMAZON LINUX 2 INSTANCE.
Sign in to your AWS Console and Click on EC2 AWS WEBSITE
Navigate to the EC2 Dashboard and Click on Launch Instance.
Choose your Server Name.
Choose the Amazon Machine Image. (A lower version would be better because they are more stable).
Using Amazon Linux 2 for this project.
- Choose Instance type and Key-Pair.
- Configure network settings and make sure these security groups are open.
- Configure storage settings.
- Then, Click on Launch Instance and the server should run a few minutes.
STEP 2: CONNECTING TO THE EC2 INSTANCE.
To connect to your server you would need a SSH-Client
I would be using MobaXterm to access my Amazon Linux 2 EC2 Instance.
To access your server using MobaXterm you would need credentials e.g.
Public IP Address from AWS Console.
Private Key (.pem) on your local computer.
Server Name (ec2-user) for Amazon Linux 2 Server.
STEP 3: PREPARE THE SERVER
Change the hostname of the server
sudo vim /etc/hostname
Press
shift Key + Z
twice to close the Vim editorReboot the server to adopt the new changes for the server.
sudo reboot
Restart the server to pick up the new hostname.
Press CTRL + R
- Make sure the server apt repo is up-to-date .
sudo apt update -y && sudo apt upgrade -y
STEP 4: INSTALL DOCKER
Install Docker and enable Docker to start on boot.
sudo yum install docker -y
Starting the Docker service.
sudo systemctl start docker
Verifying the installation.
sudo docker run hello-world
Enabling the Docker service.
sudo systemctl enable docker
Check the Docker version.
docker --version
Add User to Docker Group.
sudo usermod -a -G docker $(whoami)
STEP 5: INSTALL DOCKER-COMPOSE
- To install docker-compose.
sudo curl -SL https://github.com/docker/compose/releases/download/v4.27.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
Make the docker-compose file executable.
sudo chmod +x /usr/local/bin/docker-compose
To check the version of docker-compose installed.
docker-compose version
STEP 6: CLONE THE GITHUB REPO ON YOUR SERVER
Install git software to run git commands.
sudo yum install git -y
2. Clone the git repo using the git clone command.
git clone https://github.com/Iron-chest/wordpress-mysql-dockercompose.git
Do a syntax check on the docker-compose yaml file.
docker-compose config
Execute your docker-compose yaml file for the default docker-compose file name.
docker-compose up -d
If you receive any error message, paste these commands.
sudo chmod 666 /var/run/docker.sock
If you are using a custom file.
docker-compose -f docker-composeFileName up -d
Check if your docker container are running.
docker ps
ordocker container ls
STEP 7: ACCESS YOUR WORDPRESS WEBSITE
Access your WordPress Website on your
IPAddress:portnumber
Choose your preferred language.
Fill in the required details like Website Name, Password, and email, and Click Install WordPress.
- Login with your username and password and your Admin Page for WordPress Website should be up and running.
- Access the WordPress Website.
- You can check your phpMyAdmin Webpage.
- To stop the docker containers.
docker-compose down
Thank You for following through to the end, I hope you were able to DEPLOY A WORDPRESS WEBSITE INTO A DOCKER CONTAINER USING DOCKER COMPOSE.