Install Mysql Docker

The Docker deployment framework supports easy installation and configuration of MySQL Server. This section explains how to use a MySQL Server Docker image. Step 1 — Installing MySQL. Let's start by installing the MySQL database first. We need to have it up & running before we can connect with phpMyAdmin. We'll grab the image from the official MySQL repository on Docker Hub using docker pull command. As of writing, the latest version of MySQL is 8.0.19. If you did not use Docker before, this is a good exercise for you to start using Docker to start a simple services. In old days, if we want to use MySQL, the installation steps will be quite different in Window, Mac and Linux. However, If we use docker, the installation steps will be much more easy and similar. Following the series of blogs started by Peter Zaitsev in Installing MySQL with Docker, on deploying Docker containers running open source databases, in this article, I’ll demonstrate how to install PostgreSQL using Docker. Before proceeding, it is important to remind you of Peter’s warning from his article, which applies here as well.

In this article, we are going to see a step-by-step tutorial on how to run a MySQL database in a Docker Container.

1.Downloading a MySQL Server Docker Image

To download the image, open the command line and type this command:

The :latest tag will download the latest version of MySQL. If you want do download a specific version, simply replace the
latest (Ex: mysql-server :8.0)

2.Start a MySQL Container in Docker

Install Mysql Docker For Windows

The next step is to run a container in Docker with the MySQL image. To do this, execute the next command:

Let’s break down this command to understand it better:

Install Mysql Docker Ubuntu

  • run - will run a new command in a new Docker container
  • –name - will give a name to the new container created
  • -p - will make the internal docker port visible outside docker
  • -e - will change the root password. Here you can insert whatever password you want
  • mysql/mysql-server:8.0 - will specify what image to run in the newly created container

To verify if the container was created and running, we can execute a docker ps (process status) command:

This will list all the running containers as shown above.

In the status column of the result from above, you can see the (health: starting) mention. After the container is initialized
and ready to run, you will se it change to (healthy).

3.Connecting to MySQL Server from within the container

Install Mysql On Docker

To connect, we will first run the next command:


This will require the root password set in the previous step. After inserting the password, you should be inside MySQL

Install Mysql Docker

Type exit to leave the program.

4.Stopping the MySQL container

To stop the container, simply execute the next command:


5.Deleting the MySQL container

To delete the container, make sure that it is stopped. Then, execute this command:

Share this blog post on Twitter, Facebook, and LinkedIn

Most Viewed Posts