MariaDB Server is a cross-platform relational database that enables to access data using Structured Query Language (SQL). It is a fork of MySQL Server. Development of MariaDB was started from the original repository of MySQL. MariaDB might be a drop-in replacement for MySQL. MariaDB is an open-source project which released under the GPLv2 license.
This tutorial explains how to install MariaDB inside a Docker container in the Linux. Commands have been tested on Ubuntu.
Prepare environment
Make sure you have installed Docker in your system. If you are using Ubuntu, installation instructions can be found in the post.
Install MariaDB
- Host network
Run the following command to create a container for MariaDB that uses host network:
docker run -d --name=mariadb --restart=always --network=host \
-v /opt/mariadb/data:/var/lib/mysql \
-e MARIADB_ROOT_PASSWORD=pwd123 \
mariadb
- User-defined bridge network
User-defined bridge network can be used for listening on different port. By default, MariaDB service is listening on port 3306. It can be changed with -p
option.
docker network create app-net
docker run -d --name=mariadb --restart=always --network=app-net \
-p 8080:3306 \
-v /opt/mariadb/data:/var/lib/mysql \
-e MARIADB_ROOT_PASSWORD=pwd123 \
mariadb
Note: don't forget to change root password.
Testing MariaDB
Run the following command to open the MariaDB client and enter password:
docker exec -it mariadb mariadb -u root -p -e "SHOW DATABASES"
The command outputs all databases on server:
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
Uninstall MariaDB
To completely remove MariaDB, remove its container:
docker rm --force mariadb
Remove MariaDB image:
docker rmi mariadb
You can also remove MariaDB data:
sudo rm -rf /opt/mariadb
If a user-defined bridge network was created, you can delete it as follows:
docker network rm app-net
Leave a Comment
Cancel reply