Dockerize WordPress with themes, plugins and common configuration
Tags: docker, dockercompose
Published: 2020-02-05 05:18:27

---
title: Dockerize WordPress with themes, plugins and common configuration
published: true
date: 2019-12-10 04:37:29 UTC
tags: Docker, docker-compose
canonical_url: https://dev.to/saluminati/high-traffic-wordpress-website-with-docker-aws-ecs-code-pipeline-load-balancer-rds-efs-complete-series-43id
---

> **This article is the continuation of [WordPress with Docker, AWS (ECS, Code Pipeline, Load Balancer, RDS, EFS) Complete Series](https://dev.to/saluminati/high-traffic-wordpress-website-with-docker-aws-ecs-code-pipeline-load-balancer-rds-efs-complete-series-43id). For better understating, please start from the beginning of the series.**

In this article, we will create the following files and folders

[![](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/24061758/wordpress-directory-1.png)](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/24061758/wordpress-directory-1.png)

Let’s create files and folders

Creating Dockfile
```shell
touch Dockerfile
```

Creating development directory and docker-compose file
```shell
mkdir development && touch development/docker-compose.yml
```

Creating themes and plugins directories
```shell
mkdir themes && plugins
```

Creating config directory and uploads.ini file
```shell
mkdir config && touch config/uploads.ini
```

Creating entrypoint-child.sh file
```shell
touch entrypoint-child.sh
```


## Dockerfile

Paste the following content into the Dockerfile

```docker
FROM wordpress:latest

# Copying Themes and Plugins into the wordpress image
COPY ["themes","/usr/src/wordpress/wp-content/themes"]
COPY ["plugins","/usr/src/wordpress/wp-content/plugins"]

# Updating the configuration of wordpress image with our own
COPY ./config/uploads.ini /usr/local/etc/php/conf.d/uploads.ini

# Applying the execution right on the folders for apache
COPY entrypoint-child.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint-child.sh
ENTRYPOINT ["entrypoint-child.sh"]
CMD ["apache2-foreground"]
```


## entrypoint-child.sh

```shell
#!/bin/bash
set -euo pipefail

echo "Adding permissions"
chown -R www-data:www-data /var/www/html/wp-content &amp;
find /var/www/html/wp-content -type d -exec chmod 0755 {} \; &amp;
find /var/www/html/wp-content -type f -exec chmod 644 {} \; &amp;
echo "Permissions added"

exec docker-entrypoint.sh "$@"
```

Our WordPress Docker image ( **wordpress:latest** ) already contains an entry point. which is called **docker-entrypoint.sh**. The reason have added our custom entrypoint file into the mix is because of AWS EFS volumes for our Plugins storage on AWS. That is why we need some permissions to be added again. This entrypoint just add those permissions and then execute the image default entrypoint. Don’t worry about this for now, I will shed more light on it as we progress.

## uploads.ini config

Paste the following content into config/uploads.ini file

```ini
file_uploads = On
memory_limit = 64M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 600
```

Please change the above as per your wordpress website requirements

## docker-compose

Paste the following content into development/docker-compose.yml file

```yaml
version: '3'
services:
  wordpress:
    build: ../
    restart: always
    ports:
      - "8000:80"
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: root
      WORDPRESS_DB_PASSWORD: root
      WORDPRESS_DB_NAME: blog_db_name
      WORDPRESS_CONFIG_EXTRA: |
        /* If you want to add any extra wordpress config */
        # define('WP_ALLOW_MULTISITE', true );
    volumes:
      - wordpress:/var/www/html
  db:
    image: mysql:5.7
    restart: always
    logging:
      driver: none
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_USERNAME: root
      MYSQL_PASSWORD: root
      MYSQL_DATABASE: blog_db_name
    volumes:
      - db:/var/lib/mysql
volumes:
  wordpress:
  db:
```

We have created two service in the docker-compose file

- wordpress
- db

WordPress service is building a Docker image from the Dockerfile we have created in the begining

```shell
build: ../
```

The above line is telling the docker-compose to build the image from a Dockerfile which is on the root of this project

```yaml
ports:
  - "8000:80"
```

The above command is just mapping the 8000 port from outside world to the port 80 of this container

We are also setting some environment variables such as database credentials which are initialized in the **db** service

## Time to see something on the browser !!!

All the required files and directories have been created. Let’s start our wordpress website by running the following commands

```shell
cd development
docker-compose build
docker-compose up
```

Open your web browser and type http://localhost:8000 and you should be able to see this page.

[![](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/24062111/Screenshot_2019-12-10-WordPress-%E2%80%BA-Installation-2.png)](https://s3-ap-southeast-2.amazonaws.com/sal-blog/wp-content/uploads/2019/12/24062111/Screenshot_2019-12-10-WordPress-%E2%80%BA-Installation-2.png)


#### Next

**[Prepare AWS Security Groups for WordPress project](https://salzam.com/prepare-aws-security-groups-for-wordpress-project/)**