In this post, I will show you how to install MariaDB and phpMyAdmin using Docker Desktop on Windows 10 Home.
When you use more than one database on your computer, you often have problems with your environment settings such as TCP/IP port collision. If you want to use multiple databases (e.g. MySQL, MariaDB) or want to install specific versions of MariaDB (e.g. MariaDB 10.1, 10.2, 10.3), you need to change the ports to 3306, 3307, 3308, … for each database.
Docker can help you manage databases on your Windows-based computer. You can install databases on a Linux environment (most real-world servers are running on Linux), and you can use Linux tools to help you tune performances of your databases via WSL2 (Windows Subsystem for Linux 2). Instructions for installing performance tuning is coming in my next post!
Docker Desktop in this article runs on Windows 10 Home. Now with Windows version 2004, you can run Docker Desktop on Windows 10 Home using WSL2 (windows subsystem for Linux 2) environment.
- Docker Desktop (First, you need to install docker on your computer (If you haven’t installed it yet, you can follow this instruction (https://docs.docker.com/docker-for-windows/wsl/). If everything is ready, let’s get started.)
Step 1: Pull MariaDB and phpMyAdmin images from docker hub
Run this command to pull MariaDB docker image from docker hub.
$ docker pull mariadb
Run this command to check if you successfully pull the MariaDB image.
$ docker image
Run this command to pull phpmyadmin docker image from docker hub. After it finishes, you can check if the phpmyadmin image is successfully pulled using the previous command “docker image”.
$ docker pull phpmyadmin/phpmyadmin
Step 2: Create a MariaDB container.
Run the following command to create and start a container. Note that the parameter “-p (localPort: containerPort)” is important in this process. You can choose a specific local port but not the container port, because most software such as MySQL, MariaDB set default ports (3306) in environment settings. If you set the container other than the default port (3306), you can’t use MySQL. (You need to change the config in my.cnf file in a Docker container if you want to use another port.)
docker run --name=[container_name] -e MYSQL_ROOT_PASSWORD=[yourpassword] -e MYSQL_DATABASE=[database_name] -p 3306:3306 -d mariadb
docker run --name=mariadb -e MYSQL_ROOT_PASSWORD=a3b6c9 -e MYSQL_DATABASE=testdatabase -p 3306:3306 -d mariadb
This example sets root’s password as “a3b6c9”, which you will need to remember for the next step.
If you get the following error :
“Error response from daemon: driver failed programming external connectivity on endpoint mariadb01 (f7947a60db22243968284c8e7b68272816f462993240da78c2f8d849a6e1dc7c): Bind for 0.0.0.0:3306 failed: port is already allocated.”
make sure that port 3306 on your local computer is not already used. If the port is already used, you can change the port on your local computer that will be used to connect to the container and stop that port in services.msc (Windows key + R) and start MariaDB container again.
If you successfully create the MariaDB container, you will see this, which means that you can now use MariaDB on docker and it’s running on port 3306.
Step 3: Test that you can connect to MariaDB.
Now, to test that you can use the MariaDB, we will test by connecting to a database management tool. In this example, I use DBeaver (a database management tool). You can install DBeaver by going to https://dbeaver.io/.
Now You can use MariaDB (Enjoy ! with SELECT * FROM …………..)
Step 4: Create a PhpMyAdmin Container
Another popular database management tool PhpMyAdmin. I think if you are a web developer, you would know PhpMyAdmin (IF YOU KNOW WHAT IS XAMPP).
docker run --name [container_name]-d --link [mariadb_container_name]:db -p 8080:80 phpmyadmin/phpmyadmin
docker run --name phpMyAdmin -d --link mariadb:db -p 8080:80 phpmyadmin/phpmyadmin
check container is running
go to: http://localhost:8080/
Now, you can use phpMyAdmin that is connected with MariaDB.
If you want to install other databases or a specific version you just pull images and create a container. I think if you use Docker it is easy to manage databases on your computer because it’s like one program per one container (database) that can easily install.
In the next part, I will show you to use some tools to help you tune the performance of your database.
Thanks for reading!
- Anu Wat -