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'

services:
  joomla:
    image: joomla
    restart: always
    links:
      - joomladb:mysql
    ports:
      - 8080:80
    volumes:
      - "../:/var/www/html"
    environment:
      JOOMLA_DB_HOST: joomladb
      JOOMLA_DB_PASSWORD: example

  joomladb:
    image: mysql:5.6
    ports:
      - 3306
    restart: always
    volumes:
      - "./data:/var/lib/mysql"
    environment:
      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.

kitematic

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

Our reader's favorite picks

Joomla Docker Tutorial - Create your first joomla docker container

Creating a Joomla Docker container.

Leave review
In this tutorial we are going to learn how to set up a docker container and...
Read More
Lamp Docker Tutorial

LAMP Docker Tutorial

Leave review
Today we bring you a small pill of knowledge with the hand of Docker for we...
Read More
If you want to work remote then don't make these mistakes!

If you want to work remote then don't make these mistakes!

Leave review
Read More
Telegram Creator acuses Whatsapp of having backdoors for syping

Telegram Creator acuses Whatsapp of having backdoors for syping

Leave review
According to Durov, Whatsapp has never been secure and it has been done lik...
Read More
How app development works in developing countries

How app development works in developing countries

Leave review
Read More
This is what your UI should learn from videogames

This is what your UI should learn from videogames

Leave review
The videogame industry moves over one billion dollars on a yearly basis. It...
Read More
Suscribe to our mailing list

What is this about?

Our latest posts.

Joomla vs Wordpress

Joomla vs Wordpress

Leave review
In Hamro Dev we are experts in both Joomla and Wordpress, and in today's po...
Read More
How to use docker and wordpress

Wordpress and Docker Tutorial

Leave review
Using docker allows us to run all of our project straight in our own machin...
Read More
Using Redis and Node js 101

Node and Redis via Docker

Leave review
In this tutorial we are going to learn how to set up a small redis developm...
Read More
Answering tricky interview JS Questions

Answering tricky interview JS Questions

Leave review
This is a small comprendum of the sort of questions you may find in a Javas...
Read More
Lamp Docker Tutorial

LAMP Docker Tutorial

Leave review
Today we bring you a small pill of knowledge with the hand of Docker for we...
Read More

Related topics

Our categories.