Apple M1 Chip to work with MariaDB docker image

Malindu Hettiarachchi
3 min readOct 2, 2021

--

As you know Docker Desktop for Apple Silicon chip is currently available as the GA release. But still not all images are available to run on ARM64 based architecture. Especially the mysql image is not available. As an alternative the recommendation is to use mariadb image.

MariaDB on docker starts with choosing the latest image and then creating the container. If you follow the same steps as mentioned in MariaDB documentation and try to connect to the container from outside through the Container IP it won’t success on Mac.

I initially thought its due to my configuration issue or docker M1 version mismatch and did a re-setup from scratch. Then found out it's a docker limitations on Mac, it doesn't support on the IPs of the containers. Will sum-up the clear steps with learnings hence anyone else can get things done on their first try.

You should have Docker for M1 chip installed on your macbook already. Then use below command to download the latest MariaDB image through docker.

docker pull mariadb

Next is to create and run the container from the download image.

docker run --name testdbcontainer -e MYSQL_ROOT_PASSWORD=test -p 3306:3306 -d mariadb

To check if the container is up and running you can use below commands.

docker exec -it testdbcontainer mysql -u root -p
...
show databases;
exit;

1. Connecting to MariaDB container from outside

Here if you do a docker container inspect to get the running IP address of the container and try to connect from the IP you will get the below error:

mysql -h 172.17.0.2 -P 3306 --protocol=TCP -u root -p
...
ERROR 2003 (HY000): Can't connect to MySQL server on '172.17.0.2:3306'

The reason was a good learning and it is a limitation where you cannot access container IPs directly on Mac. You need to use localhost with port forwarding. Even you will not be able to ping to your container IP address. Read here for other limitations docker is having on MAC.

Hence the proper way of the above command to access the container on Mac:

mysql -h localhost -P 3306 --protocol=TCP -u root -p
...
mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || sys |+--------------------+4 rows in set (0.01 sec)

2. Connecting using DB Client

MySQL GUI Clients help us to connect to the container from any machine and visualize our databases. Couple of good ones are there for Mac. I tried few of these tools and my personal preference is with TablePlus. I m in favour of its simple and clear interface. On TablePlus free version can have only two tabs open but that serves my purpose at the moment. You can enter the same info you entered to connect through mysql command line client in above.

Here you have to use 127.0.0.1 as the host IP if you connect from your own PC to the DB container ( should be the IP address of your localhost and not the IP address of the docker container due to the above discussed limitation in Mac). If you connect from a different machine then it should be the IP of your mac machine combined with the mapped port.

Thank you and good luck with Docker and MariaDB on M1.

--

--

Malindu Hettiarachchi

Researcher who invests time and effort to identify effective ways to produce better quality softwares