Small Traps in Setting a Local MariaDB Development Environment by Docker

docker pull mariadb
docker run --name=learning-mariadb mariadb
docker run --name=learning-mariadb-server --env="MYSQL_ROOT_PASSWORD=your-password" mariadb
docker container rm learning-mariadb-server
docker run -it --network some-network --rm mariadb mysql -hsome-mariadb -uexample-user -p
docker network create learning-mariadb-network
docker run --name=learning-mariadb-server\
--detach \
--env="MYSQL_ROOT_PASSWORD=your-password" \
--network learning-mariadb-network \
mariadb
docker run -it --rm \
--name=learning-mariadb-client \
--network learning-mariadb-network \
mariadb \
mysql -u root -h learning-mariadb-server -p
mysql -u root -h learning-mariadb-server -p
-u root -h learning-mariadb-server -p
-h learning-mariadb-server
GRANT ALL ON *.* TO 'username'@'%' IDENTIFIED BY 'your-password';
SELECT User, Host FROM mysql.user
docker volume create `your-volume-name`
docker run --name=learning-mariadb-server\
--detach \
--env="MYSQL_ROOT_PASSWORD=your-password" \
-v learning-mariadb-dbdata:/var/lib/mysql \
--network learning-mariadb-network \
mariadb

One more thing. Another caveat

When you already have a data volume with existing data, you do not have to use MYSQL_ROOT_PASSWORD to run a mariadb-server. In the official document, it is said that this option will be ignored in any case and the pre-existing database will not be changed in any way.

docker run --detach \
--name=your-container-name \
-v learning-mariadb-dbdata:/var/lib/mysql \
--network learning-mariadb-network \
mariadb

Summary and tools you need

If you want to use Docker to run a MariaDB for local development, here is what you needed:

  1. create a network (use this directly in command line)
docker network create learning-mariadb-network
docker volume create learning-mariadb-dbdata
docker run --name=learning-mariadb-server\\
--detach \\
--env="MYSQL_ROOT_PASSWORD=your-password" \\
--network learning-mariadb-network \\
mariadb
docker run -it --rm \\
--name=learning-mariadb-client \\
--network learning-mariadb-network \\
mariadb \\
mysql -u root -h learning-mariadb-server -p
docker run --detach \\
--name=your-container-name \\
-v learning-mariadb-dbdata:/var/lib/mysql \\
--network learning-mariadb-network \\
mariadb

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store