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
  1. First, get the MySQL image

    docker pull mysql

  2. 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

  3. Now, we'll need a base image on which we'll build MySQL container. For that base image we're going to pick debian.

    docker pull debian

  4. 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

  5. We can check which images we've still now, to check images run

    docker images

You will see that debian and MySQL both images are there.

  1. 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.

  1. Now, to verify whether the container is running or not,

    docker ps

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 debian image.