Angelo
Angelo
I am Angelo. A systems engineer passionate about Linux and all open-source software. Although here I'm just another member of the family.

How to deploy MariaDB and PhpMyAdmin using Docker

Hello, friends. In this short post, you will learn how to deploy MariaDB and PhpMyAdmin using Docker. These are some simple images without so many additives, so you can by yourself edit it and improve it to your liking.

Let’s go.

Install Docker on Linux

As you can imagine, the first step is to have Docker on the system. This way, we can get started.

For this, we have several posts adapted to many distributions so that you can guide you accurately.

Once you have it, now you have to install docker-compose this package is by default in most Linux distributions. In the case of Debian and Ubuntu, you just need to run.

sudo apt install docker-compose

With this, we will be able to start.

Deploying MariaDB and PhpMyAdmin using Docker

To make this deployment a bit easier, let’s resort to a yml file for Docker Compose.

So, open a text editor and create the file

nano docker-compose.yml

And add the following content

version: '3.1'

services:

  db:
    image: mariadb:latest
    restart: always
    environment:
      MARIADB_ROOT_PASSWORD: adminpass
      MYSQL_USER: "angelo"
      MYSQL_PASSWORD: "angelopss"
    volumes: 
      - "./mariadb/data:/var/lib/mysql/data/"
      - "./mariadb/logs:/var/lib/mysql/logs/"

  
  phpmyadmin:
    image: phpmyadmin:latest
    restart: always
    ports:
      - 8080:80
    environment:
      - PMA_ARBITRARY=1
Docker Compose file for MariaDB and PhpMyAdmin
Docker Compose file for MariaDB and PhpMyAdmin

Let’s see, let’s go by parts

The first thing is that two services are raised and db is the one of MariaDB. In this service, it is indicated that we will use the image of MariaDB: latest so we will have the latest stable version of it. Then we define the environment variables that are a key for the root user, a regular user and its password.

Something important are the volumes that we will use to access, both to the data and to the logs that MariaDB generates. You can use another location, obviously.

The second service is called phpmyadmin and obviously, it is destined to PhpMyAdmin. There you only define the image to use, the port that you need to expose in your system and with which PhpMyAdmin will work. In this case, for the port 80 of the image we have exposed the 8080 that will have to be available in the firewall. Of course, you can use another one.

The PMA_ARBITRARY variable sets an arbitrary server, so you don’t have to tie PhpMyAdmin to a particular database or server.

Save the changes and close the editor. Now cross your fingers so that everything goes well.

Run in the same directory as the file

docker-compose up -d
Deploy MariaDB and PhpMyAdmin using Docker
Deploy MariaDB and PhpMyAdmin using Docker

Then, you can open your web browser and access http://your-server:8080 to see the PhpMyAdmin home page. Log in with the root user or with the normal user.

PhpMyAdmin login screen
PhpMyAdmin login screen

Of course, keep in mind that the root user is the one who has permissions to create databases and so on. If you want to change this, you will have to access the image and create a new database and give the regular user permissions on it.

PhpMyAdmin running properly with Docker
PhpMyAdmin running properly with Docker

Conclusion

In this post, you learned how to deploy MariaDB and PhpMyAdmin using Docker.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook

x