Launch MariaDB with Docker

Write a Dockerfile

First, write the Dockerfile as follows.


FROM mariadb:latest

COPY ./init.sql /docker-entrypoint-initdb.d/

VOLUME [ "/var/lib/mysql" ]

Specify the original image of MariaDB with FROM. Then COPY sends the local file ʻinit.sql to the directory /docker-entrypoint-initdb.d/in the container. The purpose of this is to place the table etc. first when launching theMariaDBcontainer. Finally,VOLUME saves the MariaDBdata in the container locally. The purpose of this is to save the save data locally so that the data will not be lost if you stop theMariaDB` container.

Prepare a table at startup

By preparing ʻinit.sql` as shown below, the table will be created when the container is started.


USE test;
CREATE TABLE test(name varchar(10));

Here, we first create a database named test. Then select the database test. Finally, we are creating a table named test. Here, the column name is only name, and its type is a variable length string.

Launch the container

After creating the above file, create a Docker ʻImage` file. Execute the following command in the directory where the above files are located.

$ docker build -t mariadb .

In addition, start the container with the following command.

$ docker run --name mariadb -e MYSQL_ROOT_PASSWORD=password -dp 3306:3306 mariadb

Here, the container name is mariadb. The database password is password. ** Without this, startup will fail. ** ** The port to open is specified by local port number: container port number. Here, both can be accessed by opening 3306 at localhost: 3306.

By the way

You can enter the container with the following command (although you can also enter it from Docker Desktop etc.).

$ docker exec -it mariadb bash

Furthermore, you can execute SQL from the command line by going inside the container and executing the following.

[email protected]:/# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.5.5-MariaDB-1:10.5.5+maria~focal binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

Recommended Posts

Launch MariaDB with Docker
Rails deploy with Docker
Run Pico with docker
Explode Docker with WSL2
Use Puphpeteer with Docker
Operate Emby with Docker
Try WildFly with Docker
Use ngrok with Docker
Run Payara with Docker
[Docker] Connection with MySQL
Php settings with Docker
Launch Docker image with initial data injected with docker-compose
Getting Started with Docker
Disposable PHP with Docker
Install Composer with Docker
Use GDAL with Python with Docker
Deploy with EC2 / Docker / Laravel
Run TAO Core with Docker
Docker management with VS Code
Set up GitLab with docker
Run Rails whenever with docker
Get started with DynamoDB with docker
Docker autostart settings with wsl2
[Docker] Rails 5.2 environment construction with docker
Spring Boot starting with Docker
Build docker environment with WSL
Version control CocoaPods with Docker
Web application built with docker (1)
I tried BIND with Docker
React environment construction with Docker
Build DynamoDB local with Docker
[Docker] Use whenever with Docker + Rails
Using PlantUml with Honkit [Docker]
Rails + MySQL environment construction with Docker
Node.js environment construction with Docker Compose
Run lambda with custom docker image
Deploy a Docker application with Greengrass
Build Couchbase local environment with Docker
Install java with Ubuntu 16.04 based Docker
Build a Node.js environment with Docker
Environment construction with Docker for beginners
[PDO → DB connection with docker, PHP]
Run SQL Server with Docker ToolBox
Easily Docker Java applications with Jib
Why use orchestration tools with Docker
Launch a stub server with WireMock
Build PlantUML environment with VSCode + Docker
Try running cloudera manager with docker
Molecular phylogenetics exercise with docker (working)
IP address interfered with Docker bridge
Build environment with vue.js + rails + docker
Read dump file with Docker MySQL
Hello World with Docker and C
General error: 1812 occurs with docker + laravel
Build Rails environment with Docker Compose
Create SolrCloud verification environment with Docker
WordPress with Docker Compose on CentOS 8
[Google Cloud] Getting Started with Docker
[SRE / Docker] Start control with Dockerize
Create Laravel environment with Docker (docker-compose)
Operate a honeypot (Dionaea) with Docker