Install WordPress on Docker LEMP Stack with Letsencrypt SSL

August 17, 2016 | By in DEVOPS, LINUX HOWTO
| Reply More

WordPress is an opensource software, which you can use to create your beautiful website, blog, or app. Hundreds of community volunteers has built this core software. And there are thousands of plugins and themes available for this to transform your website into the one in your imagination.

In this article, I'm explaining on how to install WordPress on a Docker container with LEMP stack and run this securely with SSL on my Ubuntu 16.04 server. You can use Docker Compose to easily run WordPress in an isolated environment built with Docker containers.


  • Docker installed Ubuntu 16.04 server
  • Require a FQDN hostname
  • SSL certificate for your hostname
  • LEMP stack

You can refer my previous article to know how I installed SSL for my hostname using Let's Encrypt software.

Creating WordPress Dockerfile

We need to create our Dockerfile to automate our installation as per our requirements. This docker file comprises  a docker image which will automatically install the wordpress, LEMP stack and other required packages for our application. Apart from that we need to copy some of the volumes from our docker host to enhance the domain security with SSL and a pre-defined vhost configuration for our hostname.



huahaiy/lemp-wordpress : This image will automate our wordpress installation with LEMP stack.
/srv:/srv : Configure SSH agents are per our image
conf : This folder contains our saved secured Nginx configuration
/etc/letsencrypt & /opt/letsencrypt contains our certificate details and letsencrypt scripts.
/var/lib/mysql : Determines the database location for our installation.

PS : We can exclude the volumes which we don't prefer to copy over as per our convenience.

Moreover, it exposes the ports 80 and 443 of docker container to the host's port 8081 and 8080 respectively.

Creating our WordPress Container

The above docker file tells docker to run a container using the  huahaiy/lemp-wordpress image, mount the specified volumes from the docker host and expose ports  to run the application. We can run this command to compose our docker container.

root@www:~# docker-compose up
Pulling lemp (huahaiy/lemp-wordpress:latest)...
latest: Pulling from huahaiy/lemp-wordpress
012a7829fd3f: Pull complete
41158247dd50: Pull complete
916b974d99af: Pull complete
a3ed95caeb02: Pull complete
1527345bbd21: Pull complete
1eb53890aa28: Pull complete
464ea636b922: Pull complete
8ba7392dc2a5: Pull complete
4cf87d5c765a: Pull complete
a9174a1a303a: Pull complete
d5c8e4f50350: Pull complete
Digest: sha256:8a92f263ca2095ddd4c8fe07c8d8306af2a16728f1e598897a8d62844f24352a
Status: Downloaded newer image for huahaiy/lemp-wordpress:latest
Creating root_lemp_1
Attaching to root_lemp_1
lemp_1 | % Total % Received % Xferd Average Speed Time Time Time Current
lemp_1 | Dload Upload Total Spent Left Speed
100 7591k 100 7591k 0 0 5441k 0 0:00:01 0:00:01 --:--:-- 5441k
lemp_1 | wordpress/
lemp_1 | wordpress/wp-settings.php
lemp_1 | wordpress/wp-cron.php
lemp_1 | wordpress/wp-comments-post.php
lemp_1 | wordpress/wp-activate.php
lemp_1 | wordpress/wp-admin/
lemp_1 | wordpress/wp-admin/link-parse-opml.php
lemp_1 | wordpress/wp-admin/js/

On running this docker compose file, it will pull the specified docker image from our docker hub and download all the required packages for our installation. This image will install WordPress on LEMP stack.  The LEMP stack is a group of software that is used to serve our web applications. It includes Nginx with PHP and MySQL.

Installation stages

Initially, as we stated before, it downloads all required packages as specified in our docker image. Then it starts with the installation of LEMP stack and extract the downloaded WordPress files to the default domain document root at "/usr/share/nginx/www/".

During the installation phase, it set the MySQL root password and creates a  database namely "wordpress" with the same user and sets its password as shown for WordPress installation.


Finally, it updates our WordPress configuration file with these details to enhance the WordPress installation from the browser on the container.


Once the installation is complete, we can verify our container status as below.

root@www:~# docker ps
73e10f1c0b94 huahaiy/lemp-wordpress "/docker-entrypoint.s" 21 hours ago Up 9 minutes 3306/tcp,>80/tcp,>443/tcp root_lemp_1

Confirm the Installations

Now we can login to our container and confirm the software installations.

root@73e10f1c0b94:/# nginx -v
nginx version: nginx/1.4.6 (Ubuntu)
root@226485fa2d44:/# service nginx status
* nginx is running
root@73e10f1c0b94:/# php -v
PHP 5.5.9-1ubuntu4.13 (cli) (built: Sep 29 2015 15:24:49)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
root@73e10f1c0b94:/# mysql -V
mysql Ver 14.14 Distrib 5.5.44, for debian-linux-gnu (x86_64) using readline 6.3

We need to enable Nginx to run PHP scripts by default. Let's take a look on the Vhost configuration for my domain to enable my SSL and PHP.

server {
# SSL configuration
listen 443 ssl default_server;
listen [::]:443 ssl default_server;

root /usr/share/nginx/www;
ssl_certificate /etc/letsencrypt/live/;
ssl_certificate_key /etc/letsencrypt/live/;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;

# pass the PHP scripts to FastCGI server listening on
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

# With php5-cgi alone:
# fastcgi_pass;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;

WordPress installation

Our docker compose file have just created a docker container with wordpress installation files downloaded on our domain document root and setup the required platform to run our installations. Now we need to complete our installation via web interface securely. You can access your WordPress blog at https://Docker hostname:8080/. This will redirect to our WordPress installation folder.


Select your language and click "continue" to proceed further.


We can provide the required details here as shown in the snapshot and proceed with "Install WordPress" option . This will complete our installation  and we can login to our WordPress Admin Panel with the credentials,


Hurray!! Our WordPress docker container is ready to go. I hope this article is really helpful for you. Thank you for reading this :) I would recommend your valuable comments and suggestions on this. Have a Good day!


Share This :

Free Linux Ebook to Download

Leave a Reply

Commenting Policy:
Promotion of your products ? Comment gets deleted.
All comments are subject to moderation.