MySQL is a famous relational database management program that can run on various platforms. Docker is a software forum where developers can build, run, and share applications with the help of containers. Running MySQL in a Docker container is a convenient and flexible way to deploy and manage database applications. It also provides isolation, portability, and security for MySQL applications.
This article will demonstrate the step-by-step procedure to install MySQL 5.7 in a Docker container.
What are the Steps to Install MySQL 5.7 Version in a Docker Container?
To install MySQL 5.7 in a Docker container, follow the below-listed steps:
- Pull the MySQL image with the “7” tag using the “docker pull mysql:5.7” command.
- Verify the downloaded image.
- Run the MySQL image in a container using the “docker run -d –name mySql-cont -e MYSQL_ROOT_PASSWORD=<password> mysql:5.7” command.
- View the MySQL container for verification.
Step 1: Pull MySQL Image
First, pull the official MySQL image with the tag “5.7” from the Docker Hub using the provided command:
The above output shows that the “MySQL 5.7” image has been downloaded successfully.
Step 2: Verify the Downloaded Image
Then, write out the following command to verify whether the image has been downloaded or not:
In the above output, the MySQL image can be seen with the tag “5.7”.
Step 3: Run MySQL Image in a Container
Now, build and run the MySQL container using the “mysql:5.7” image by executing the “docker run -d –name <cont-name> -e MYSQL_ROOT_PASSWORD=<password> <image-name>” command.
Here:
- The “-d” option runs the container in detached mode.
- The “–name” option is utilized to define the container name which is “mySql-cont” in our case.
- The “-e MYSQL_ROOT_PASSWORD” sets the root password for MySQL to “Pass123”.
- “mysql:5.7” is the Docker image to use:
This command has started a new container named “mySql-cont” running MySQL version “5.7” in the background.
Step 4: Verification
Lastly, ensure that the MySQL container is started and running successfully using the below command:
The above output indicates that MySQL 5.7 is successfully installed in a Docker container.
Conclusion
To install MySQL 5.7 in a Docker container, first, pull the MySQL image with the “5.7” tag using the “docker pull mysql:5.7” command and verify it. Then, execute the “docker run -d –name mySql-cont -e MYSQL_ROOT_PASSWORD=<password> mysql:5.7” command to run the MySQL image in a container. This article has demonstrated the step-by-step procedure to install MySQL 5.7 in a Docker container.