MariaDB is an open-source relational database. It is utilized by many websites, like Wikipedia and DBS Bank. MariaDB can run on Docker, a framework that allows users to create and run containers on any system. Users can also easily deploy and manage different versions of MariaDB on different systems.
This post will explain in detail the steps to set up a MariaDB Docker deployment.
How to Set up a MariaDB Docker Deployment?
A container is a compact, secure setting in which a particular daemon and the software it requires executing. Docker simply contains the packages that are absent from the underlying system. It does not virtualize the entire system. However, it increases Docker’s efficiency and flexibility.
To set up a MariaDB Docker deployment, users will need to follow these steps.
Prerequisite: Check the Installed Docker Version on the System
Before installation, you can check if Docker is installed and running via the following command in a terminal:
The output shows that Docker “20.10.23” version is installed in the system.
Step 1: Download a MariaDB Image
For downloading a MariaDB image through the Docker Hub repository, you can search for an image by typing the following command in a terminal or browsing the Docker Hub website. More specifically, an image is a template that contains the software and configuration for a container:
docker search mariadb
Step 2: Create a Container from the Image
Next, create a container from the image you downloaded. For instance, use the “docker run” command to create and start a container with various options, such as specifying a name, a network, an environment variable, or a port mapping.
For example, create a container named “some-mariadb” with the user “example-user” and a password “my_cool_secret”, and map port 3306 of the container to the port 3306 of the host by typing the command in a terminal:
docker run --detach --name some-mariadb --env MARIADB_USER=example-user --env MARIADB_PASSWORD=my_cool_secret --env MARIADB_ROOT_PASSWORD=my-secret-pw -p 3306:3306 mariadb:latest
- The “–detach” option runs the container in the background.
- The “latest” tag specifies the latest version of MariaDB.
Step 3: Connect to MariaDB
You can also use the “docker exec” command to run commands inside the container and enter the password “my-secret-pw” when prompted:
docker exec -it some-mariadb mysql -u root -p
The output shows that MariaDB deployment has been set and users can execute any command in the MariaDB prompt.
Bonus: Manage your Container
To manage your container and data, you can use various Docker commands to start, stop, pause, restart, or remove your container. For example, you can type “docker stop some-mariadb” to stop the container, or “docker rm some-mariadb” to remove it.
Note that removing a container will also delete all the data stored in it unless you use a volume to persist your data outside the container.
To set up a MariaDB Docker deployment, utilize the image from Docker Hub. After that, configure the database settings, create a user and a database, and connect to the database from another container. By using Docker, users can easily deploy and manage our MariaDB instances in a portable and scalable way. This guide has explained how to set up a MariaDB Docker deployment.