Let's Encrypt, Docker, and WordPress

Created at 2016-08-18 Updated at 2016-11-02 Tag Docker / Let's Encrypt / Wordpress / Mattermost / NGINX

Intro

I had a specific problem that i wanted to solve: setting up a wordpress installation that had HTTPS, and it had to be inside of a docker container. Seemed challenging.

Luckily for me, the project HTTPS-PORTAL is is working order and being actively developed!

Using Let’s Encrypt’s certificate automation, I was able to set up an HTTPS wordpress install in under five minutes. Here are some reasons why sites should be using HTTPS:

  • HTTPS helps prevent intruders from tampering with the communications between your websites and your users’ browsers. Intruders include intentionally malicious attackers, and legitimate but intrusive companies, such as ISPs or hotels that inject ads into pages.

  • HTTPS prevents intruders from being able to passively listen in on the communications between your websites and your users.

  • It is much cheaper and faster to imlement because of the Let’s Encrypt project!

I followed this tutorial to get me up and running with my wordpress install. I had some problems understanding how to write a docker-compose file, but the blog author was very quick in helping to correct my mistakes.

Compose

Here is what my docker-compose.yml file contained, minus the real password:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# docker-compose.yml for my_wordpress site
https-portal:
image: steveltn/https-portal
ports:
- 80:80
- 443:443
links:
- wordpress
environment:
- "DOMAINS=containerize.us -> http://wordpress" #maps https-portal to the wordpress image
- "PRODUCTION=true" #ensures that the certificate will be recognized as valid by web browsers
wordpress:
image: wordpress
links:
- db:mysql
db:
image: mariadb
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: '<secure_password>'

In the docker-compose.yml directory, run the command to start the containers:

1
docker-compose up

After the server generates a TLS Diffie-Hellman key and spins up the WordPress instance, we have our WordPress site installed!

Increase Upload Allowance

Now let’s insert some media. While you could just embed everything from an external site like youtube and imagur, it is nice to have the option to host your own assets. Right now, the upload limit is a puny 2MB. Let’s change it to 64MB.

To enter the running container, type:

1
docker exec -i -t mywordpress_wordpress_1 bash

To install the nano text editor, type:

1
2
apt-get update
apt-get install nano

Create the file php.ini in you WordPress root directory.

1
vi php.ini

Once in, paste these lines:

1
2
3
upload_max_filesize = 64M
post_max_size = 64M
memory_limit = 64M

Stop the running containers…

1
docker-compose stop

And restart them in detatched mode

1
docker-compose up -d

Hooray, our upload limit is now increased! We can now upload media up to 64MB.

My Running Sites (Currently offline)

You can visit the site I generated this way at https://news.containerize.us

Also, using keys a generate with HTTPS-PORTAL, I created a Mattermost instance.

Click here to join my Containers Mattermost group.

Site by Jackson Stokes

Hide