Hello everyone, welcome to Docker Tutorial for beginners. Today I am going to deploy MySQL Server Containers using Docker. I am using Ubuntu 18.04 hosting the Docker container. If you run Docker on a different machine or OS, there should be no differences. You may also interested in How to run MS SQL Server Container using Docker. So let’s get started.
What you will learn
- Run MySQL Server Container with remote access enabled
- Connect to MySQL Server from other computers
Steps to Deploy MySQL Server Containers Using Docker
First, I hope you have Docker installed on your computer. You can install it on a local computer or on a network computer. Please navigate to my previous guide to install Docker on several operating systems:
Now, open Terminal and execute this command. You may need to execute this command as root.
docker run -p 33061:3306 --name mysql-server -e MYSQL_ROOT_PASSWORD=12345 -e MYSQL_ROOT_HOST=% -d mysql/mysql-server:latest
After you run this command, docker daemon will start downloading mysql image from the internet. Now let’s check our new containers.
Make sure the new containers is there
As you can see, my new mysql container is there.
Logging in to the server
Now let’s try to log in to the server from a Terminal console
docker exec -it mysql-server mysql -uroot -p
You will be prompted for the root password.
Connect to MySQL Server Containers from other computers using MySQL Workbench
Now let’s try to connect to our MySQL containers from another computer. I am using MySQL Workbench. Create a new connection and enter the following information:
- Hostname: 0.0.0.0
- Username: root
- Port: 33061
- Password: 12345
Please note that when I tried to use localhost in the Hostname, it didn’t work.
Now it should works
After spending about one hour, finally, I can run my MySQL Docker Containers and enable remote access to it. Thanks to everyone in this forum that led me to fix my confusion. Now I have a working MySQL Server on my Docker Containers. Deploy MySQL Server Containers is not that complicated. With few practices, I and you could get used to it. Thank you