• hey@aysharshad.com
  • Trondheim, Norway.
DevOps
Getting Started with Docker​: Easy Guide to Deploy WordPress on Docker Container

Getting Started with Docker​: Easy Guide to Deploy WordPress on Docker Container

Simplest way to start learning a new tech or tool in IT is to start a Project!

So this guide is aimed to help you create a Dockerized App for the first time. Simply follow the short and simple instructions given below but try to start with your own project instead of just replicating this one. You can start understanding the basics by studying this one then replace tools and services in this script to get started with your own project.

In this guide we will be setting up a WordPress Website with MySQL Server as Database Server. If this is your first project as a beginner maybe you can start with changing Database option and see how you need to change the script.

What is Docker?

Docker is an open source tool that helps engineers to  containerize their applications. Containerizing an application allows it to learn on any environment anytime because it replicates the virtual base OS environment along with necessary libraries and dependencies.

Docker Compose File

Docker File is a way to practice Infrastructure as Code. You can simply spin your infrastructure by writing a code and running it in your Systems. Infrastructure as Code allows DevOps engineers to replicate the environment on any System just by running the script.

Getting Started with Docker

Watch the following video to help you get started with Docker. Then you can follow the guide for your first ever Dockerized App Project.

Tutorial

Create Directory for Project
PowerShell
mkdir [Project-Directory-Name]
cd [Project-Directory-Name]
Pull Images from Docker Hub

Pull the WordPress and MySQL Images from Docker Hub. You can follow this step for other services as well. Just search your specific service or database in Docker Hub and pull the image using the following Command: 

PowerShell
docker pull wordpress
docker pull mysql
Docker-Compose.yml File

Run the following Docker-Compose.yml file from your project Directory using the following command:

PowerShell
docker-compose up
Docker
version: '3.0'
 
services:
  #Database
  db:
    container_name: MySQLServer
    image: mysql:latest
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: P@33w0rd**19
      MYSQL_DATABASE: W0rdPr3ss
      MYSQL_USER: W0rdPr3ss
      MYSQL_PASSWORD: W0rdPr3ss
    networks:
      - wpsitenetwork
  #WordPress
  wordpress:
    container_name: WordPressServer
    depends_on:
      - db
    image: wordpress:latest
    ports:
      - '8000:80'
    volumes: ['./:/var/www/html']
    restart: always
    environment:
      WORDPRESS_DB_NAME: W0rdPr3ss
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: W0rdPr3ss
      WORDPRESS_DB_PASSWORD: W0rdPr3ss
    networks:
      - wpsitenetwork
 
networks:
  wpsitenetwork:
volumes:
  db_data:
error: Content is protected. You are automatically reported to the Authorities!