Docker, MariaDB

docker-compose.yml YAML for MariaDB Docker Container

This post shows how to create and use a docker-compose YAML file to generate a MariaDB Docker container with initial user accounts. First, we need to install Docker for Windows. Then, use its docker-compose to process our YAML file. We tested everything using MariaDB 10 and Windows 10.

Create A docker-compose YAML File

Next, we create a docker-compose YAML file as shown below. Use any text editor and, for simplicity, save it as docker-compose.yml. Notice we set some environment variables to create an initial user in MariaDB – MYSQL_USER and MYSQL_PASSWORD. Moreover, we used environment variables to specify the root account’s password and our database. Also, we specified the version of MariaDB, which is version 10 for this post.

We could use another label or name for our networks. In this post, we are using turreta_network. In case we want a different label, replace all instances of turreta_network with something else.

We use the same port MariaDB uses. We could change these ports, though.

Create Docker Container Using Docker-Compose

Then, we create a MariaDB Docker container using the docker-compose YAML and the docker-compose application. To achieve that, we first open a Windows Command Line prompt and cd to the directory where the docker-compose.yml  file is. Then, run the following commands.

First, pull the image from Docker Hub to the local machine.

Then, create and run a MariaDB container using the following command.

With  Docker-compose YAML, we can easily recreate the same MariaDB Docker container whenever we need a fresh copy.

This post is part of the Docker For Developers tutorial.


Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.

You Might Also Like