Install Mysql Docker Container

I’m a Developer who last 6 years using C#, Asp.Net, SQL Server and Oracle.
And now I’m trying to learn Laravel Php Framework.
Training for Laravel need of using MySQL. I decide to use Docker image of MySQL.

Install Mysql Client In Docker Container

Here is an article about installing docker on ubuntu: How to install docker on ubuntu? Mysql container run in background, root user's password is 'test'. docker run -rm -it -e MYSQLROOTPASSWORD=test -d mysql.d Run container in background and print container ID.rm Automatically remove the container when it exits. In this article, I am going to show you how to use Docker Compose to create a MySQL container and access it using phpMyAdmin 5, the web-based MySQL admin interface. I will also show you how to access the MySQL database server running in a Docker container from DataGrip IDE. Pull the MySQL docker container. Pulling a container image is really easy. We just need to open the docker hub website, search for the MySQL image we want to pull and execute the pull command in the command prompt. After entering the Pull command, docker will start downloading the latest version of the MySQL image. Connect to the MySQL docker container. Make sure to install the MySQL client package before connecting to MySQL server. Apt-get install mysql-client. Within the container, start the MySQL client by running the command. Docker exec -it containername mysql -uroot -p. Provide root password when asked for.

1. step, download and install Docker Community Edition for Windows

2. step, test Docker does work correctly
c:> docker run hello-world
If Docker running properly go to the next step.

Install mysql in docker containerInstall mysql docker container

3. step, download and run mysql container
c:> docker run –name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=pasw123456 -d mysql/mysql-server:latest

Install Mysql Docker Container

4. step, try to access to mysql container, learn IP address of the container
List running Docker containers, you will see Container ID, Image, Names, … info
c:> docker ps -a
Running mysql Docker container ID is 9535aa43b64d
Inspect all information about mysql container using this Container ID
c:> docker inspect 9535aa43b64d
You will see “IPAddress”: “172.xx.xx.xx” in my case this is 172.17.0.2
The basic test to access container is using Ping command
c:> ping 172.17.0.2
Reply from 172.17.0.2: Destination host unreachable.
Ping statistics for 172.17.0.2: Packets: Sent = 4, Received = 0, Lost = 4 (100% loss)
Why I can’t access the container?
Because my Windows 10 Host system IP address is 192.168.1.101 Docker mysql container address is 172.17.0.2.
They are on different IP subnets and can’t communicate with each other.
To solve this problem I need to define a new route for my Windows host system.
This route definition will help Windows host to reach to the Docker mysql container.

Install and run mysql8.0 container docker run -p 3307:3306 -name mysql8.0 -e MYSQLROOTPASSWORD=root -d mysql:8.0 remarks: -P map the port of the local host to the docker container port (3307 is used because port 3306 of the local host is occupied by other versions) - Name container name naming -E configuration information, configure the.

5. step, add route definition on Windows 10 to access mysql Docker container
Open Command Prompt as Administrator and run route command
c:> route /P add 172.17.0.0 MASK 255.255.0.0 10.0.75.2
Test again communication between the host and mysql container
c:> ping 172.17.0.2
Reply from 172.17.0.2: bytes=32 time<1ms TTL=63
Finally, we can communicate with the mysql Docker container.

Install Mysql In Docker Container

6. step, connect o mysql with Database Workbench tool
I try to connect but got a message, “Can’t connect to MySQL server on ”
The reason for this message is mysql not configured for remote connection.
I can connect only from localhost to mysql.

7. step, connect to running mysql container and configure mysql for remote connection
Connect to mysql Docker container :
c:> docker exec -it 9535aa43b64d bash
Connect to mysql server :
mysql -u root -p
List user and host access information :
SELECT host, user FROM mysql.user;
Create a mysql user ‘root’ that can connect to mysql from anywhere.
CREATE USER ‘root’@’%’ IDENTIFIED BY ‘pasw123456’;
GRANT ALL PRIVILEGES ON *.* TO ‘root’@’%’ WITH GRANT OPTION;
I now again trying to connect and again I get a different error message.
Error message: ‘Authentication plugin ‘caching_sha2_password’ cannot be loaded’

8. step, change mysql password type to ‘mysql_native_password’
ALTER USER ‘root’@’%’ IDENTIFIED WITH mysql_native_password BY ‘pasw123456’;

Install Mysql In Docker Container

Finally, I can connect to mysql container and can create a database, tables and views.