Containerize MySQL and phpMyAdmin using Docker Containers
This tutorial provides all the steps required to containerize MySQL and phpMyAdmin using Docker Containers.
We can containerize our applications using Docker to have a separate installation of the required packages with the application-specific versions independent of the underlying operating system. We can use Docker Containers to make our application portable so that we can simply move it to another system having docker. This tutorial provides all the steps to containerize MySQL and phpMyAdmin using Docker containers.
Windows - How To Install WSL 2 (Windows Subsystem for Linux) with Ubuntu On Windows 10 and How To Install Docker Desktop On Windows 10. Optionally you may follow How To Change Docker Data Path On Windows 10.
Install MySQL and phpMyAdmin
In this step, we will configure and install MySQL and phpMyAdmin using the official images. Create the docker-compose.yml at the root of your project directory as shown below.
Now, run the command docker-compose build to build the application.
cd <path to project>/helloworld
mysql uses an image, skipping
phpmyadmin uses an image, skipping
We also need to run the command docker-compose up to launch the application as shown below. It will pull the MySQL and phpMyAdmin images and take time for the first time. The subsequent launches will be faster.
# Launch Application
Pulling mysql (mysql:8.0.27)...
8.0.27: Pulling from library/mysql
ffbb094f4f9e: Pull complete
df186527fc46: Pull complete
fa362a6aa7bd: Pull complete
5af7cb1a200e: Pull complete
Status: Downloaded newer image for mysql:8.0.27
Pulling phpmyadmin (phpmyadmin/phpmyadmin:)...
latest: Pulling from phpmyadmin/phpmyadmin
69692152171a: Pull complete
2040822db325: Pull complete
2e982de2b8e5: Pull complete
Status: Downloaded newer image for phpmyadmin/phpmyadmin:latest
Creating mysql ... done
Creating pma ... done
Attaching to mysql, pma
Now, try to access phpMyAdmin from the Browser using the URL http://localhost:8085. It should show the phpMyAdmin home page as shown in Fig 1.
Now, login to phpMyAdmin using the username as root and the root password configured in the docker-compose.yml. Also, leave the server blank. It should show the phpMyAdmin home page as shown in Fig 2.
We can press Ctrl + C to stop the containers.
# Press Ctrl + C
Gracefully stopping... (press Ctrl+C again to force)
Stopping pma ... done
Stopping mysql ... done
We can also use MySQL Workbench installed locally using port 3306 to access the MySQL database running in the Docker container.
This tutorial provided all the steps to containerize MySQL and phpMyAdmin using Docker containers.