Docker Networking Example
As you already read our previous tutorial Docker Networking. In this tutorial, we will create a small docker network with 2 docker containers as follows.
> MySQL – A relational database server.
> PHPMyAdmin – A web-based interface to manage MySQL server.
In this tutorial, you will learn how to access MySQL server using PHPMyAdmin running on different containers.
1. Create Network
First of all, create a new docker network. Use the below command to create a new bridge network named my-bridge-network.
2. Run MySQL Container
Now, run a new MySQL docker container. Set the default root user password with MYSQL_ROOT_PASSWORD variable as shown in the below command.
After creating the container add this to our network.
Now view the new IP address of the MySQL container, which is required in the next step.
3. Run PHPMyAdmin Container
Now run a new Docker container of phpmyadmin using the following command. Change the PMA_HOST value with the IP address of MySQL container IP address get in the last step.
Add this container to our network.
4. Inspect Our Network
As you have attached both containers to our new network. Let’s inspect the current network settings.
You will get the result some like below.
5. Allow MySQL to PHPMyAdmin Host
The default MySQL doesn’t allow remote hosts to connect. So allow phpmyadmin for MySQL connection. Get shell access to your MySQL container using the below command.
Login to your MySQL server using the password provided during instance creation.
Create a new user with phpmyadmin host IP address. In my case phpmyadmin host ip address is ‘172.21.0.3‘ as shown in the above step.
6. Access MySQL with PHPMyAdmin
Finally, Connect your docker host system on port 8080 to access phpmyadmin web user interface.
Use MySQL credentials created in the above step to log in to PHPMyAdmin.
0 Comments
CAN FEEDBACK
Emoji