# Wordpress app dockerization

You are here because you want to dockerise your wordpress. As containerization made it easy to deploy without installing anything except docker.

#### Prerequisite

Install [**docker**](https://docs.docker.com/install/#server) and [**docker-compose**](https://docs.docker.com/compose/install/), then you are ready to go.

**Here is the tree for application**

Create the application folder structure with the following

mkdir wordpress  
touch docker-compose.yml  
touch .gitignore

Folder structure looks like this

|----  wordpress/  
|---   docker-compose.yml  
|---   .gitignore

### Step1:

Place the wordpress content in the folder wordpress by Downloading the latest wordpress from [*https://wordpress.org/download/*](https://wordpress.org/download/)

OR

You can also download using wget with

```
wget [http://wordpress.org/latest.tar.gz](http://wordpress.org/latest.tar.gz)
```

```
tar xfz latest.tar.gz
```

After placing the wordpress content in the folder, tree structure looks like this

|----  wordpress  
          |---wp-admin/  
          |---wp-content/  
          |---wp-includes/  
          |---index.php  
          |---license.txt  
          |---readme.html  
          |---wp-activate.php  
          |---wp-blog-header.php  
          ...........  
          ............  
|---   docker-compose.yml  
|---   .gitignore

### Step2:

Place the following yml configuration into the ***docker-compose.yml*** file

version: '3.1'  
services:  
   wordpress:  
      image: wordpress  
      restart: always  
      ports:  
         - 8080:80  
      volumes:  
         - ./wordpress:/var/www/html  
      environment:  
         WORDPRESS\_DB\_PASSWORD: DoKRteST

mysql:  
      image: mysql:5.7  
      restart: always  
      volumes:  
         - ./db-mysql/:/var/lib/mysql  
      environment:  
         MYSQL\_ROOT\_PASSWORD: DoKRteST

In the above configuratio, we are using official docker images [**wordpress**](https://hub.docker.com/_/wordpress/)**,** created and maintained by [**the Docker Community**](https://github.com/docker-library/wordpress).

Running MYSQL as the container with the configuration as

mysql:  
      image: mysql:5.7  
      restart: always  
      volumes:  
         - ./db-mysql/:/var/lib/mysql  
      environment:  
         MYSQL\_ROOT\_PASSWORD: DoKRteST

Here we are using the official docker image mysql, restart set to always if it goes down. Mouted the volume for Database persistancy, if the container goes down and restarts we should maintain the data persistancy. Environment for setting the Password of the mysql. [To know more about the mysql docker configuration](https://hub.docker.com/_/mysql/), indetailed explanation about the mysql as docker container.

### Step 3:

To run the application with

docker-compose up -d

\# OR, If your .yml file is name is different then

docker-compose -f your-docker-compose-filename.yml up -d

Give it a minute to run and open the application on [http://localhost:8080](http://localhost:8080)

#### Here are some helping points to understand more about the YML configuration for docker-compose.

> **image: wordpress**

> “ When we run the container, the execution layers comes to the above line, it will check for the image in the image cache of the local machine, for the first time it won’t be available in the local image cache, then it will check with docker official dockerhub then it downloads it. “

> **restart: always**

> This lines is for mainting the application to restart when app goes down it self heals it self and runs by it own.

> **ports:  
>  — 8080:80**

> Application withing the container runs on the port **80,** we are mapping the container port to 8080 to the host ip.
