Skip to content

Iron-chest/DEPLOY-A-WORDPRESS-WEBSITE-INTO-A-DOCKER-CONTAINER

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DEPLOY A WORDPRESS WEBSITE INTO A DOCKER CONTAINER

WORDPRESS

WordPress is a web content management system. It was originally created as a tool to publish blogs but has evolved to support publishing other web content, including more traditional websites, mailing lists and Internet forum, 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 is developed by Docker, Inc.

DOCKER CONTAINER

A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings.

STEP 1: LAUNCH AND CONFIGURE AN AMAZON LINUX 2 INSTANCE.

  1. Sign in into your AWS Console and Click on EC2 AWS WEBSITE.
  2. Navigate to the EC2 Dashboard and Click on Launch Instance.
  • Choose the Server Name. Choose the Server Name
  • Choose the Amazon Machine Image. (A lower version would better because they are more stable). Choose the Amazon Machine Image
  • I would be using Amazon Linux 2 for this project. Choose the Amazon Linux 2
  • Choose Instance type and KeyPair. Choose Instance type and KeyPair
  • 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 be running in few minutes.  Click on Launch Instance

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 some 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.  Connecting to the ec2 Instance

Step 3: PREPARE THE SERVER

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

 Change the hostname of the server 2. Restart to server to adopt the new hostname for the server.

sudo reboot

 Restart the server 3. Restart the server

Press CTRL + R

hostname changed 4. Make sure the server apt repo is up-to-date

sudo yum update -y

Update server packages

STEP 4: INSTALL DOCKER

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

 Install Docker 2. Starting the Docker service

sudo systemctl start docker

Start Docker service 3. Verifying the installation

sudo docker run hello-world

Verify Docker installation 4. Enabling the Docker service

sudo systemctl enable docker

Enable Docker 5. Check the Docker version

docker --version

Docker Version 6. Add User to Docker Group

sudo usermod -a -G docker $(whoami)

Add User to Docker Group

STEP 5: INSTALL DOCKER-COMPOSE

  1. To install docker-compose
sudo curl -L https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose

Install Docker-compose 2. Make the docker-compose file executable

sudo chmod +x /usr/local/bin/docker-compose

Make Docker-compose executable 3. To check the version of docker-compose installed

docker-compose version

Check 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

Install git software 2. Clone the git repo using the git clone command

git clone https://github.com/Iron-chest/wordpress-mysql-dockercompose.git

Clone git repo 3. Do a syntax check on docker-compose yaml file

docker-compose config

Check if Docker-compose is valid 4. Execute your docker-compose yaml file for default docker-compose file name

docker-compose up -d

Execute Docker-compose file 5. If you are using a custom file

docker-compose -f docker-composeFileName up -d

For a custom docker-compose file name 6. Check if your docker container are running

docker ps

OR

docker container ls

check if container is running

STEP 7: ACCESS YOUR WORDPRESS WEBSITE

  1. Access your WordPress Website on your IPAddress:portnumber
  2. Choose your preferred language Access WordPress Website
  3. Fill in the required details like Website Name, Password, email and Click Install WordPress. Input required details
  4. Login with your username and Password and your Admin Page for WordPress Website should be up and running. Login to Admin Page
  5. Your WordPress Website is up and running. WordPress site is running
  6. You can check your phpMyAdmin Webpage. Login to phpMyAdmin WebPage
  7. To stop the docker containers
docker-compose down

Stop docker containers