13. Running WordPress & Database Containers on Portenta X8

Learn how to run a database and WordPress container on the Portenta X8

Overview

The Arduino Portenta X8's robust features are ideally complemented by Docker containers, simplifying various applications. This tutorial demonstrates how to deploy a WordPress web server on the Portenta X8, leveraging containers for web service and database management.

You will learn to set up and access a WordPress site hosted on the X8 via a web browser.

Goals

  • Prepare the necessary files for Docker container deployment
  • Deploy and activate the Docker containers on the Portenta X8
  • Access and configure the WordPress site hosted on the Portenta X8

Required Hardware and Software

Instructions

Begin by ensuring your Portenta X8 is ready for use, following the setup guide in the User Manual's Out-of-the-Box Experience.

Creating the docker-compose.yml File

Our WordPress setup involves a multi-container approach, integrating both the WordPress and a MariaDB database server containers. The WordPress container uses Apache as the web server, merged within the container for easy deployment.

To direct this setup, we will craft a docker-compose.yml file describing the configurations for both WordPress and MariaDB containers, including essential settings like usernames, passwords, time zones, and database names. For security, ensure the default passwords are substituted with stronger alternatives in the provided configuration template.

Complete docker-compose.yml File

In this section, you can find the complete docker-compose.yml file that we will be using for this tutorial.

1version: "3.9"
2
3services:
4 db:
5 image: mariadb:latest
6 container_name: mariadb
7 environment:
8 - PUID=1000
9 - PGID=1000
10 - MYSQL_ROOT_PASSWORD=Wordpress
11 - TZ=Europe/London
12 - MYSQL_DATABASE=Wordpress
13 - MYSQL_USER=Wordpress
14 - MYSQL_PASSWORD=Wordpress
15 volumes:
16 - db_data:/var/lib/mysql
17 restart: unless-stopped
18
19 Wordpress:
20 depends_on:
21 - db
22 image: wordpress:latest
23 volumes:
24 - Wordpress_data:/var/www/html
25 ports:
26 - "8000:80"
27 restart: always
28 environment:
29 WORDPRESS_DB_HOST: db
30 WORDPRESS_DB_USER: Wordpress
31 WORDPRESS_DB_PASSWORD: Wordpress
32 WORDPRESS_DB_NAME: Wordpress
33volumes:
34 Wordpress_data: {}
35 db_data: {}

Now, let's prepare our Portenta X8 by creating a directory for our docker-compose.yml file, which can be downloaded here.

Installing The Containers

Begin by creating a directory for the Docker setup, naming it wordpress-test. Navigate into this directory and either copy the docker-compose.yml file into it or create the file directly within.

To create the file on the device, use

cat > docker-compose.yml
, paste the contents, and exit with
CTRL + C
. To transfer the file from your computer, use the following command, making sure to replace
<path to docker-compose.yml file>
with the actual file path:

1adb push <path to docker-compose.yml file> /home/fio/wordpress-test

Alternatively, you could place the

docker-compose.yml
file inside the
wordpress-test
directory and push the file using the following command:

Alternatively, if the docker-compose.yml is already inside the wordpress-test directory on your computer, use:

1adb push .\wordpress-test\ /home/fio

Choose the method that best suits your workflow.

cd into correct directory
cd into correct directory

Access Docker with administrative privileges by executing

sudo su -
, with
fio
as the default password.

Ensure no conflicting containers are running on your intended ports by inspecting current containers with

docker ps -a
. Remove any active containers by first stopping them with:

1docker stop <container id>

Then removing them with:

1docker rm <container id>

If you want more information about handling containers on your Portenta X8, take a look at our Managing Containers with Docker tutorial.

With the setup directory ready and no port conflicts, begin the container installation with:

1docker compose up -d

The

-d
flag runs the containers in the background; omitting it will tie the container's lifecycle to the terminal session.

The installation of the WordPress and MariaDB containers will begin and may take some time. To monitor the installation process, use:

1docker-compose logs -f

Upon completion, your WordPress site will be accessible from the Portenta X8.

Containers install progress in the terminal
Containers install progress in the terminal

Connecting to the WordPress Site

Accessing your WordPress site on the Portenta X8 is straightforward. Use the following URL format, composed with your Portenta X8's unique id and port, in your browser:

1http://portenta-x8-<uuid>.local:<port>

Replace

<uuid>
with your Portenta X8's unique identifier and
<port>
with the port you have allocated for the WordPress container. You can find your device's
<uuid>
in the setup guide within the User Manual's Out-of-the-Box Experience, through terminal commands involving
adb
, or by visiting
http://192.168.7.1:8000
on Windows and Linux (use
http://192.168.8.1:8000
for MacOS).

Upon establishing a connection, your terminal will display details similar to those below.

Terminal printout during connection
Terminal printout during connection

Your browser will then present the WordPress setup page, allowing you to commence the configuration process.

Wordpress setup site
Wordpress setup site

You are now free to go through the WordPress setup process and configure it however you like.

Removing the Containers

Should you need to remove the containers, navigate back to the

/home/fio/wordpress-test
directory and use the commands below based on your requirements.

To remove the containers while retaining your WordPress data:

1docker compose down

To delete both the containers and all associated data:

1docker compose down --volumes

Confirm the removal by executing

docker ps -a
and verifying that the WordPress and MariaDB containers are no longer listed.

Conclusion

In this tutorial, we went through installing and running a WordPress and database container on the Portenta X8. We then accessed the WordPress site on our X8 through our web browser. Now, you can set up your WordPress site on your X8 device and access it from another device.

Troubleshooting

  • If the containers are not being installed or running correctly, check if any other containers are currently running on the same ports as the ones used by the WordPress container. You can check it with

    docker ps -a
    .

  • If there is any issue running docker commands, ensure you are using

    sudo
    before the commands or having root access using:
    sudo su -r
    with password:
    fio
    .

  • If you cannot connect to the site when everything is running, you can double-check the X8's IP address. Run the command

    ip -h address
    in the adb shell. This will display the X8's IP address via USB and Wi-Fi®. Try connecting via those IP addresses if all the rest fails.

Suggest changes

The content on docs.arduino.cc is facilitated through a public GitHub repository. If you see anything wrong, you can edit this page here.

License

The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.