Deploying a WordPress Website into a Docker Container Using Docker-Compose

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.

  1. Sign in to your AWS Console and Click on EC2 AWS WEBSITE

  2. Navigate to the EC2 Dashboard and Click on Launch Instance.

  3. Choose your Server Name.

choose 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.

Amazon Linux 2 AMI

  • Choose Instance type and Key-Pair.

choose instance type and Key-pair

  • Configure network settings and make sure these security groups are open.

configure network settings

  • Configure storage settings.

configure storage settings

  • Then, Click on Launch Instance and the server should run a few minutes.

Launch instance button

STEP 2: CONNECTING TO THE EC2 INSTANCE.

  1. To connect to your server you would need a SSH-Client

  2. I would be using MobaXterm to access my Amazon Linux 2 EC2 Instance.

  3. DOWNLOAD MOBAXTERM

  4. 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.

Mobaxterm terminal

STEP 3: PREPARE THE SERVER

  1. Change the hostname of the server sudo vim /etc/hostname

  • Press shift Key + Z twice to close the Vim editor

  • Reboot 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

  1. Install Docker and enable Docker to start on boot. sudo yum install docker -y

  2. Starting the Docker service. sudo systemctl start docker

  3. Verifying the installation. sudo docker run hello-world

  1. Enabling the Docker service. sudo systemctl enable docker

  2. Check the Docker version. docker --version

  3. Add User to Docker Group. sudo usermod -a -G docker $(whoami)

STEP 5: INSTALL DOCKER-COMPOSE

  1. 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
  1. Make the docker-compose file executable. sudo chmod +x /usr/local/bin/docker-compose

  2. To check the version of docker-compose installed. docker-compose version

STEP 6: CLONE THE GITHUB REPO ON YOUR SERVER

  1. 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
  1. Do a syntax check on the docker-compose yaml file. docker-compose config

  2. Execute your docker-compose yaml file for the default docker-compose file name. docker-compose up -d

  3. If you receive any error message, paste these commands.

sudo chmod 666 /var/run/docker.sock
  1. If you are using a custom file. docker-compose -f docker-composeFileName up -d

  2. Check if your docker container are running. docker ps or docker container ls

STEP 7: ACCESS YOUR WORDPRESS WEBSITE

  1. Access your WordPress Website on your IPAddress:portnumber

  2. Choose your preferred language.

  3. Fill in the required details like Website Name, Password, and email, and Click Install WordPress.

  1. Login with your username and password and your Admin Page for WordPress Website should be up and running.

  1. Access the WordPress Website.

  1. You can check your phpMyAdmin Webpage.

  1. 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.