Protect Your Data: Run MariaDB using Docker

Oct 28, 2022

MariaDB is a completely free database server, which gives access to data through the underlying Structured query Language (SQL). MariaDB comes with security features including passwords, roles-based access control, and more to protect your information.

To set up MariaDB and grant data access to the users, you have to create an account on a database server. You can choose between choosing an online service provider or perhaps managed or shared hosting solutions.

This tutorial will teach you how to utilize MariaDB using its Docker container. It is possible to create and run the database server, and link to your WordPress website.

What's Docker?

The majority of containers run the operating system on your personal computer to act as host. That means that the host's kernel can access the hardware and software, including memory processors, CPUs, and CPUs along with the file system. Therefore, it does not require traditional virtualization like virtual computers. There are several advantages of making use of Docker to host an MariaDB instance.

  • It's got a tiny digital footprint that allows for an efficient use of the resource of the system.
  • It's secure and lets developers use their applications on test and production using only some minor changes.
  • This is a system that could be adapted that allows the sharing of resources.
  • The host is flexible. You can host multiple containers within the same host.

How do I deploy MariaDB using Docker

In this this section, you'll create containers to use MariaDB with the help of Docker. Then, you'll be introduced to the containers technology offered by Docker. Docker works on any version of Windows, macOS, and Linux distributions. To follow this tutorial, you'll need to have Windows 10/11, Ubuntu 20.04 as well as a macOS X machine to follow the directions.

1. Install Docker

Ubuntu 20.04

The first step is to update Ubuntu's package list.

sudo apt-get update

After that, you can allow access to online repository websites through HTTPS.

sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
Installing docker through the terminal.
Then, you can connect your Docker's GPG key.
sudo mkdir -p /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

Then, you can add the Docker repository.

echo deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Then, update Ubuntu's packages to integrate Docker's repository.

sudo apt-get update

You can then, to download and run Docker Engine.

sudo apt-get install docker-ce

If you're using a different Linux distribution like Debian or Fedora you should refer to the official guidelines for Installing Docker in Linux.

Windows 10/11

Docker works for Windows 10 or 11 using Windows Subsystem for Linux Version 2 (WSL 2.) as the backend. Follow these steps for installing Docker.

Before you can start, you must allow your Virtual Machine Platform feature on the Windows machine. This lets you install WSL 2 and install and use an emulator Linux version of the program on your Windows computer.

Then, Install WSL.

Visit the Microsoft Store to download and install Ubuntu 20.04.

Then, you'll be able to download Docker Desktop. Docker Desktop for Windows. Start downloading the file and install the application.

Following installation, type "Docker Desktop" from your taskbar and open the application.

( Note:You'll need to install PowerShell onto your console before you can make use of the Docker command line.)

macOS X

Docker can be downloaded to be used for use on macOS PCs through in the Apple App Store. Two installers are available which target Intel and Apple chip.

First, download the correct installer from one of these sites. After that, double-click the installer and it will open the download .dmg file.

Following that Drag then Drop the Docker icon in the Apps folder.

Once you have done that, launch the Docker app from within your Application directory. Then, follow the instructions to configure the parameters.

When the installation process has been completed, after it has been installed Click the Docker icon that appears in the screen's status bar to launch the program.

Make use of the default terminal when you want to run the start Docker commands.

2. Download the MariaDB Image

An Docker image is an array of commands and configurations which make up an Docker container. It is the only one accountable of installing the required elements required to run an application. The MariaDB official image can be found on the Docker Hub.

To download MariaDB's image for download Docker Hub, you'll need to use Docker Pull. Docker Pull command:

docker pull mariadb

It is also possible to search for the list of downloaded Docker images using these commands:

Docker images

The output will be the command:

Listing Docker images.
List Docker image listings.

3. Create a container

Containers are software elements that include the entire code, all dependencies in addition to the software utilized by the system in running a program. The image is downloaded in order to build an MariaDB container.

docker create mariadb --name mariadb-wp -i -t

It also creates the MariaDB container dubbed mariadb-wp. It is so because the -i flag allows for the creation of an interactive session. Additionally using the option of the -t option results in a non-trusted terminal. The official document provides information about all possible variables.

4. Stop, Run, or shut down the Container following which you may end the container.

Docker gives developers the freedom to design environments using a wide range of choices. In this chapter , we'll set up MariaDB's container using the variables that are required to define the settings for the particular container.

MariaDB has a range of variables that you can configure, like passwords for databases and database names, and the individuals who access the database. To learn more about the possible environment variables, head to the documentation of Docker for MariaDB.

docker run -d --name mariadb-wp -p 3306:3306 -v '/path/on/host/:/var/lib/mysql' -e "MARIADB_ROOT_PASSWORD=" -e "MARIADB_DATABASE=wordpress" -e "MARIADB_USER=wordpress" -e "MARIADB_PASSWORD=" mariadb

This command creates MariaDB's root password, and also the password of the user who is in the database and database. Then, it runs MariaDB on port 3306. It is possible to stop an application in a container via the command below:

docker stop mariadb-wp

Additionally, you're capable of closing any application that is running in a particular context by using the following commands:

docker blocks the mariadb-wp

5. Connect the containerized MariaDB an WordPress Site

The directory that is the root on the WordPress website is accessible to access your wp-config.php file in your editor to look for codes. Search for the code line that defines the variables employed in the database. Change the code according to the following example. Be sure to include your Database's username, password and also the port number during the process of creating MariaDB. MariaDB container.

define('DB_NAME', 'wordpress'); define('DB_USER', 'wordpress'); define('DB_PASSWORD', ''); define('DB_HOST', 'http://localhost:3306');

After you've exported your database, insert the dump inside the container.

docker exec -i mariadb-wp sh -c 'exec mysql -u root -p "$MARIADB_ROOT_PASSWORD" 

The docker execut command allows developers to run shell commands in the container. The database was moved to MariaDB via exporting a file using the command above.

6. Create a new blog post for Your WordPress Site

After that, we'll create a test blog post with administrator accounts on this account. WordPress administrator account to test the integration.

After that, log into WordPress and select "Posts" >>> Start a New. Fill out the form in the manner shown below. Then, you can press to publish. Once you have created the post, simply click "View Post" to open the newly-published post.

Adding a new post in WordPress Gutenberg editor.
A process for creating a new entry on WordPress. WordPress editor.

That's it! to it!

7. MariaDB along with Docker along with Dev

To begin, download the application then install it and start Dev onto your personal PC. It offers three options to build your own personal WordPress website: transfer an existing site from another , or design a custom website.

Dev's new create new site screen.
The Dev's Create New Screen to the site.

Making the first WordPress site is as simple as filling in a straightforward form , and clicking to create a site.

Dev's new WordPress site creation screen.
Dev's new WordPress page design screen.

You've successfully created an containerized WordPress site using Dev!

Summary

Docker is an easy-to-use program to containerize software, that handles databases such as MariaDB. Its minimalistic environments help ensure that the performance of the system is maintained however, they do not compromise functionality.

The video tutorial demonstrated the process of installing Docker and to set up MariaDB and connect a WordPress website to your containersized MariaDB database. You also learned how to utilize Dev to create the containerized WordPress site.

Reducing time, costs and enhance the performance of your site

  • Help is available immediately 24/7 support from WordPress hosting experts 24 hours a day.
  • Cloudflare Enterprise integration.
  • Reaching a global audience with 35 data centers across the world.
  • Optimization via our integrated Application to track performance.

Article was first seen on here

This post was first seen on here