Containerized WordPress, Migration, and SSL


The world witnessed the popularity of containerized applications. Docker provides good isolation and is of good portability. It also could be the basic item in a distributed system. In this post, I introduced

  1. how to create a WordPress site in docker;
  2. how to migration WordPress;
  3. how to make the site secure via SSL;


The official docker of wordpress provides a good end-to-end solution. But here, I prefer to build my own docker container to have better control.

Create a LAMP Container

WordPress lies on the LAMP stack: Linux, Apache, MySQL, PHP. We are lucky that there is a good open-sourced image available.

sudo docker run -it \ 
-p "80:80" -p "443:443" -p "3306:3306" \
-v ${PWD}/app:/app \
-v ${PWD}/mysql:/var/lib/mysql \
--name tech-blog-container mattrayner/lamp:latest

It is a common practice that not store data in containers. Thus, the CMD script in this image will create the corresponding folders. app will be your WordPress folder. mysql will store the persisted data of your database. You can also use docker Volumn and NFS from cloud providers to increase the availability and reliability of your data.

You will get a random password for the user admin. Modify it by phpmyadmin. Visit the site http://DOCKER_ADDRESS/phpmyadmin using the initial password and follow this post to modify password.

Create a WordPress Database

As we know, WordPress uses the relational database. We need to provide an accessible database and user. Use phpmyadmin to create a table and edit the privilege of the user admin to grant all operations.

Create a Fresh WordPress or Migrate from Old Sites

We have two choices here.

Create a Fresh WordPress

Download the compressed file. Unzip them into the app folder. Visit http://DOCKER_ADDRESS/. Then follow the instruction of WordPress to finish the installation.

Migrate from Old Sites

Use the great plugin Duplicator to firstly create a package and an installing script. Then copy these two files into app. Visit http://DOCKER_ADDRESS/ and follow the instruction of duplication.

Install Certificates and Enable SSL

I have a previous post for centos and Apache 1. There are some changes on Ubuntu and Apache 2.

  1. Apply for an SSL certificate. I applied a free personal SSL certificate from Tencent Cloud.
  2. Download the certificate and sent it to the server;
  3. Enable SSL a2enmod ssl;
  4. Modify the default configuration to

    <VirtualHost *:443>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html
        SSLEngine on
        SSLCertificateFile /
        SSLCertificateKeyFile /
        SSLCertificateChainFile /1_xxx.crt
        ... # keep the same
        <Directory /xxx>
  5. Restart the container;
  6. Finally use the handy plugin Really Simple SSL to enable encryption of your site.

Leave a Reply

Your email address will not be published. Required fields are marked *