Quickly Spin Up MariaDB With Docker Compose

Quickly Spin Up MariaDB With Docker Compose

Learn How to Install MariaDB Using Docker Compose

In this tutorial, we'll learn how to install MariaDB using Docker-Compose. By using Docker-Compose, we can configure an image the way we want and can turn the image on and of as needed.

Setup

Create a new directory for your MariaDB project. Inside of this directory, create a data directory and a docker-compose.yml file.

Project_Folder_For_Database
|---data
|___docker-compose.yml

Inside of the docker-compose.yml file paste this:

    version: '3.7'
    services: 
      database:
        container_name: docker-local-mariadb
        image: mariadb
        volumes:
          - "./data:/var/lib/mysql"
        restart: always
        ports:
          - 3306:3306
        environment:
          MYSQL_ROOT_PASSWORD: 0123456789

Start the Container

To start the container run this command:

 docker-compose up -d

Stop the Container

To stop the container run this command:

 docker-compose down
 

Persisting Data

Whenever MariaDB modifies any data it will be persist locally inside of your data directory.

Run Commands Inside of the Container

To run Bash commands run this command:

docker-compose exec database bash

This will give you shell access to the container.

Conclusion

In this short tutorial, we'll learn how to spin up MariaDB with Docker-Compose and how to get shell access to the container.

Did you like it? Why don't you try also...

Docker MySQL, PostgreSQL, and MongoDB

Docker MySQL, PostgreSQL, and MongoDB

Learn how to use Docker to install MySQL, PostgreSQL, and MongoDB

Quickly Spin Up PostgreSQL With Docker Compose

Quickly Spin Up PostgreSQL With Docker Compose

Learn How to Install PostgreSQL Using Docker Compose

Quickly Spin Up MongoDB With Docker Compose

Quickly Spin Up MongoDB With Docker Compose

Learn How to Install MongoDB Using Docker Compose