Creating a Joomla Docker container.

In this Joomla Docker tutorial we are going to learn how to set up a docker container and install a fully functional Joomla site in under five minutes.

What is docker?

For those of you who are not familiar. Docker is a container virtualization system with a fast-growing popularity due to its power and ease of use.

The main idea behind docker is to create small containers that act independently and connect them between. Watch this episode from TechSquidTV if you are not familiar with docker, or if you rather...

If you haven't done so, register in docker hub and download docker desktop. At this point, we recommend you follow the steps in their online tutorial before you continue reading. However, we'll keep it short, so you can give this a try first and learn more later.

Remember: Docker Desktop uses Windows 10 pro's hyper-V .  If you don't have Windows 10 pro, then you will have to download Docker Toolbox 

Joomla Docker Tutorial

Create an empty folder wherever you wish to work and then add to it a subfolder named ops. Navigate to it and create the following docker-compose.yml file.

version: '3.1'

    image: joomla
    restart: always
      - joomladb:mysql
      - 8080:80
      - "../:/var/www/html"
      JOOMLA_DB_HOST: joomladb
      JOOMLA_DB_PASSWORD: example

    image: mysql:5.6
      - 3306
    restart: always
      - "./data:/var/lib/mysql"
      MYSQL_ROOT_PASSWORD: example

This piece of code will be launching two services, one for joomla and another one for the database named joomladb. The links: part specifies that the service will be connecting to the joomladb:mysql service.

The image is telling docker to pull the joomla image from the docker hub. This image is basically a small linux server with apache and a fresh install of joomla.

The "ports" section defines that docker shall reroute the port 80 from the application to the port 8080 of the hosting machine (in this case , your laptop / PC). With ports you open the connections via that port from all machines. So watch out because in our example we are opening the port 3306 for everyone to listen to.

I like to do this in development mode so I can access the database using other sql explorers like Navicat SQL. It just makes everything so much more comfortable. Without this directive, then only the joomla server will be able to connect to the joomladb mysql service.

Containers for the linked service are reachable at a hostname identical to the alias, or the service name if no alias was specified.

"Volumes" is mounting one route from the hosting machine to the route specified into the container. In this case, we will be re-routing our parent folder (which will become our project folder) to the /var/www/html where apache stores its website files.

As you can also see, we do the same thing for the joomladb service, so we save the database files inside of our own folder (this way , we can carry all of our website in one single folder and fire it up with a simple docker command).

"Environment" tags system environment variables for the containers and it's pretty self intuitive.

now navigate via your command line interface to the ops folder and run the command:

docker-compose up

And you will see how in console the joomla database image and the joomla php/apache server are fired up. You now have two docker instances running. If you run the command docker service ls you will see them listed. We will talk about how to run this service in a swarm mode later in this tutorial.

Setting up the joomla site.

Head on to localhost:8080 -- the address may depend on your local machine. If you cant figure out what the local IP is, try downloading Kitematic for docker. It's a really simple interface that shows you all of your docker instances.


If you click on the Settings tab and then Hostname / Ports then you'll reach the ip.

kitematic ui

Head to your browser and proceed with the joomla installation.

Remember the credentials must match with the environment variables set up in the yml file. So in this case, username is root (since it has not been specified), hostname is joomladb, password is example. Hit next, next and you will have a fresh working joomla app.

joomla install

Remember that "volume" part we talked about earlier? If you head to your project folder you'll find all of your joomla installation files there, and the mysql data tables stored in ops/data.

joomla dir

Restoring a Joomla Site

Now, the options here are simple enough. You can either transfer your entire joomla site via FTP / SFTP from your host to this folder (replacing all of the files that you need to) and dump your SQL tables and data to your local mysql server using any sql explorer. NOTE: In this case make sure your parameters in configuration.php match those of your system. A quicker way is to install akeeba backup manager, which allows you to create backup files of your entire site with a simple click

akeeba backup

Install akeeba in your site via package download or through the "install from web" tab in Joomla.  You'll also need to download Akeeba Kickstart. A small php script that will help you restore a .jpa file into your system.

Once you have created a backup for your website in akeeba, download the JPA file and place it in the root of your project directory. Do the same with the akeeba php script and language file found in Akeeba Kickstart Core.

With this done,  simply run Kickstart.php (localhost:8080/Kickstart.php) and follow the on screen indications. Remember that akeeba will be transplanting your original website into your docker virtual machine, so pay special attention to the credentials and database access when akeeba kickstart asks you to fill in the blanks.

Why docker? What makes it so powerful?

The power within docker resides on the fact that it's a "language" for building virtual scalable systems. Let's say you wanted to add a mail server and an FTP connection to your website. Easy, simply editing the original docker-compose.yml to add the corresponding images and links would suffice. Sure, you wouldn't probably be able to configure it correctly at first, but after toying with it a bit you'd easily get the hang of it. There's also hundreds of tutorials over the internet as well as many images and projects. And Docker hub allows you to even share your images. In this example we are using built in images for joomla and mysql, but you can build your own images by yourself, compile them and run them in docker terminal.

using the containers in swarm mode

Another sick feature that docker has is that it allows you to run these containers in swarm mode, so multiple threads take care of your multiple services. This makes it extremelly easy to scale as your app grows. There is a whole tutorial of this that you can find here.

to run the containers in swarm mode, simply navigate to the ops folder and type

docker swarm init (if your node is not part of a swarm yet)

docker stack deploy -c  docker-compose.yml joomla 

There is much to learn so if you don't feel familiar with these, head over to the getting started tutorial at docker

Be the first to comment

Our reader's favorite picks

Subscribe to our newsletter

Let us send you spam from time to time. Yes, it is a bit of Spam, but interesting Spam, supreme quality spam to be honest!

Email *