Run mariadb and Joomla together in docker

So after wrangling with the official docs for the Mariadb and Joomla docker images and pestering ChatGPT for debugging my errors, I've managed to come up with an improved tutorial for making mariadb work with joomla. The tutorial is ran on Linux Mint 21 Vanessa, and it should work with Ubuntu Jammy LTS-based distributions.

By Ace Z. Alba

Published on May 11, 2023, 1:34 pm

Category: tutorial

Tag: automation, cli, docker, joomla, mariadb

I wanted to use this TechRepublic tutorial with a catch: I wanted to use env files and I wanted to use Mariadb. Joomla recommends mysql5.6+, but JoomlaShack said that the latest MariaDB works fine. So after wrangling with the official docs for the Mariadb and Joomla docker images and pestering ChatGPT for debugging my errors, I've managed to come up with an improved tutorial for making mariadb work with joomla.

The tutorial is ran on Linux Mint 21 Vanessa, and it should work with Ubuntu Jammy LTS-based distributions.

Setup docker

# Install docker
sudo apt-get install docker.io -y

# add your user to the docker group
sudo usermod -aG docker $USER

# Make the system aware of the new group with:
newgrp docker

Craft your .env file

Env files are used to automatically populate configuration values in certain commands. It has it's own pros and cons, but in our case, we are using env files because we want to keep our bash history clean and leave sensitive data out of it.

Create a joomla-config.env file and fill in the following values:

# joomla-config.env

# mariadb
MARIADB_ROOT_PASSWORD=your-strong-password
MARIADB_USER=joomla
MARIADB_DATABASE=joomla_db
MARIADB_PASSWORD=your-mariadb-user-password

# joomla

# check this value with `docker inspect joomladb | grep IPAddress`
# after you have `docker run` your joomla database.
# if the value happens to be different, update this with that value.
JOOMLA_DB_HOST=172.18.0.2

# same as MARIADB_USER
JOOMLA_DB_USER=joomla

# same as MARIADB_PASSWORD
JOOMLA_DB_PASSWORD=your-mariadb-password

# same as MARIADB_DATABASE
JOOMLA_DB_NAME=joomla_db

JOOMLA_TABLE_PREFIX=joo_

You can name the env file anyway you want. But do save it and do note its location. We are going to assume that you saved the env file in your home folder, i.e. ~/joomla-config.env.

Run the docker images.


# pull the official docker images
docker pull mariadb
docker pull joomla

# create your docker network
docker network create joomla-network 

# create a volume for the mariadb image
docker volume create mariadb-data

# check is mariadb is running on your computer. if it is running 
# stop it to free up port 3306.
sudo systemctl stop mariadb

# Create your joomla database named joomladb 
# attached to the joomla-network
# and bound to the mariadb-data volume
# running on exposed ports 3306:3306
docker run -d --name joomladb -p 3306:3306 -v mariadb-data:/var/lib/mariadb --network joomla-network --env-file ~/joomla-config.env mariadb:latest --wait_timeout=28800

# Check running docker containers to see if joomladb is running with exposed ports.
docker ps

# run the following command to double-check the ip address of joomladb.
# check if it is similar to the ip address in your env file. if not, replace it.
docker inspect joomladb | grep IPAddress 

# create a volume for your joomla installation
docker volume create joomla-data

# run your joomla image named joomla-dev
# with volume bound to joomla data
# attached to joomla-network
# running on exposed ports 8080:80
docker run -d --name joomla-dev -p 8080:80 -v joomla-data:/var/www/html --network joomla-network --env-file ~/joomla-config.env joomla:latest

# Check running docker containers to see if joomla-dev is running with exposed ports
docker ps

Your joomla installation should now be accessible from localhost:8080. check it on your preferred browser.

Dealing with quirks.

Remember the joomla variables in your env file, you are going to plug some of it into the joomla installation process. I don't quite understand yet why this is the case, because I know, or I think I know, that you do still need the env file values when running the docker image.

You will have to add a new super user and super user password different from that of the env file while installing Joomla. Once you go to the database configuration setup, you'd have to deal with the following.

One particular quirk is that Joomla increments your hostname. Since our database is hosted on 172.18.0.2, we must decrement it by one before plugging it in, like 172.18.0.1.

Another would be the connection timed out error. Right now I am still figuring out how to fix this. I thought I figured it out only that the connection followed through after sometime. I re-entered 172.18.0.2 again for the database hostname and it works frustratingly enough. And here I was already about to tamper with the container.

There you have it. Obviously the following setup is good for local development. I think. I'll update this if I find a less tinker-y way to deal with this.