In this article I'm gonna show you how to build MySQL Docker container image. This article assumes that you've some basic knowledge about Docker.
To run MySQL on Docker we would need to do the following
- Install Docker engine on your computer
- Download MySQL image from Docker Hub
- And run the container
First, get the MySQL image
docker pull mysql
You'll need to set up your credentials and specify path for MySQL
docker run -d --name=mysql1 -e MYSQL_ROOT_PASSWORD=’mypassword’ -v /storage/mysql1/mysql-datadir:/var/lib/mysql mysql
docker run -d --name=mysql2 -e MYSQL_ROOT_PASSWORD=’mypassword’ -v /storage/mysql2/mysql-datadir:/var/lib/mysql mysql
Now, we'll need a base image on which we'll build MySQL container. For that base image we're going to pick
docker pull debian
Now that we've base image, we'll pull MySQL image, you can specify version of your choice. I've chosen the latest 5.7
docker pull mysql:5.7
We can check which images we've still now, to check images run
You will see that
MySQL both images are there.
Now that we've all of our images, we need to run the container. To run container
docker run -d --name=mysql-test-container -e MYSQL_ROOT_PASSWORD=’my_password’
You'll need to specify root password of MySQL.
Now, to verify whether the container is running or not,
Which will show you the Container Id and the image it is running.
There you have it. You've successfully created
MySQL docker container based on