#1 Installing WordPress on a Raspberry Pi with docker-compose in under 10 minutes

Jumping to the meat and potato a short set of instructions are presented on how you can have a WordPress instance up and running in under 10 minutes on your Raspberry Pi.

Preperation / Prerequisite

To start off: what you want is a domain name. Since you will be hosting your Raspberry Pi from home and most likely will not have a static IP you also need to tell your domain provider about your changing IP. Luckily no-IP provides both a DDNS service and free domain names. My router also had an option to inform no-IP about my changing IP.

Also don’t forget to forward the ports 80 and 443 which will be incoming traffic to your website. If you are going bigger and get your own domain name you could configure Cloudflare as your nameserver. By establishing a CNAME link to your free domain name at no-IP your new domain name will automatically resolve to the dynamic IP address. An advantage using Cloudflare is, that as a content delivery network, it can cache your website. Additionally it also provides TLS certificates.

Now i assume you already managed all this and have your Raspberry with an installed OS, mine is Raspbian, ready to go .

Lets get started

First we need to install docker on our Raspberry Pi:

curl -sSL https://get.docker.com | sh

Now we want to install docker-compose. It helps us to run multiple containers with one configuration file.

sudo apt-get install docker-compose

We can now procceed to clone the repository

git clone https://gitlab.com/nm_hung93/dockerized-wordpress-on-raspberry-pi.git

For this setup i am using:

We could now configure the mount points of our docker-compose.yml. Per default they will be created in the same folder in which we cloned the repository.

It is possible to create a database when initiating the MariaDB container. This can be done through injected environment variables which we specify in /data/env_variables/mysql_credentials.

Now being still in the root folder of the repository we can download WordPress:

curl -sL http://wordpress.org/latest.tar.gz | tar --strip 1 -xz -C data/wp/www

Navigate to our WordPress installation folder and copy the wp-config-sample.php and edit it. If you are still in your root folder it should look like this:

cd data/wp/www/
cp wp-config-sample.php wp-config.php
nano wp-config.php
inside the wp-config.php file should be a line which looks like in this picture

Change the settings accordingly to our initiated database:

    • ‘database_name_here’ into blog
    • ‘username_here’ into UserX
    • ‘password_here’ into 123456
    • ‘localhost’ into mariadb

Save the file with CTRL+X and accept saving the file with Y.

Now we are all set. Navigate into our root folder (of the repository) again and run docker-compose with

 docker-compose -f docker-compose.yml up -d
    • -f specifies the file
    • -d means detached meaning it runs in the background

The Console should look like this:

Now find the IP address of your Raspberry Pi for example with:

ip addr show

And look out for eth0 or wlan0 depending on your used network interface. Mine is 192.168.2.2. We can now go to another machine inside our network and insert this IP address into our browser.

SUCCESS we did it

Now the next steps you could do are :

  • mount the folders to another directory
  • edit the Caddyfile such as commenting tls off, and replacing :80 with yourwebsite.com to actually serve your website on https
  • edit the /data/env_variables/mysql_credentials file to have more customized database credentials

<<< Previous: #0 Introduction to Docker and WordPress

>>> #2 Containerized WordPress: General troubleshooting and Migration

6 thoughts on “#1 Installing WordPress on a Raspberry Pi with docker-compose in under 10 minutes”

  1. Very well documented and easy to understand, nice work! Looking forward to your next post!

    1. Exactly, Caddy does provide an automatic integrated service which provides free TLS certificates provided by Let’s Encrypt.

      In another group project i observed that many people struggled getting a trusted certificate for their webservices. In this case, if you let Caddy handle all the traffic, it can automatically provide free TLS certificates and act as a reverse proxy to route traffic to the original destination of your webservices.

  2. Hi there, terrific post. I am trying it as of now, being a neophyte in docker and docker-compose and wanting to serve a few very low traffic websites from my Pi it is perfect.
    A few comments that come up while following it:

    – root folder: it was not immediately clear to me if root folder was the root of he Pi filesystem or the base dir of what I had pulled from git. it made sense having a look at where the data folder was and took it from there.
    – with regard to mysql credentials, instead of having a file /data/env_variables/env_file I fount a mysql_credentials file. I guess it’s that one

    I have been wating to look into docker-compose for a while. But containerization really shines when you try and have more than one copy of some service running. i.e. runnig two distinct blogs on the same machine. It would really be appreciated if you could show us (me? 🙂 ) how to be able to do so, leveraging docker-compose, where to touch and what to change to do so ….. it would make for a great blog post sequel. Many thanks

    1. Hey Massi B. ,
      thank you for your kind comment and feedback – i do appreciate it! 😀
      Using Docker and Docker-Compose is indeed thrilling but also has a steep learning curve if you never actually worked with such a tool as i experienced it myself with days of sleepless nights. But it really pays off because everything is just so clean and neatly structured.
      Your Use-Case of running two WordPress instances does not necessarily call for two separate containers. What you actually want is, that the one webserver serves two different types of contents depending on the target URL. This can be achieved by configuring the Caddyfile pointing to different mounted folders. (The mount points are again specified in the docker-compose.yml)
      This might then look like this

      website1.com {
      root www/
      }

      website2.com {
      root www2/
      }

      If you need any help with the configuration feel free to ask 🙂

      Best Regards
      Hung

Leave a Comment

Your email address will not be published.