Docker Mysql example

Installation Of Mysql in Docker

In this tutorial we will learn how can we install mysql in docker and interaction with mysql within docker container.

For demo purpose we will create database and table and insert a row in table within docker container

Follow below steps for demo

  • First you check do you have mysql image in your docker container.To check just run
  • docker images

    It will show all images in your docker.I already have in my docker.If you don't have ,run below command

    docker pull mysql

    Above command will pull image from docker hub.

  • After getting image we will install that image in container
  • docker run --name mysql-container -e MYSQL_ROOT_PASSWORD=admin mysql:latest

    mysql-container is container name.

    -e is used for environment variable.

  • Now execute
  • docker ps

    It shows that our mysql is running

  • Now we will go to shell mysql.Execute command
  • docker exec -it mysql-container mysql -uroot -p

    mysql-container is the name of running container,in our case mysql container that we created earlier. It will ask about password which you gave during mysql container.In our case admin

  • Now we are in mysql shell,there we can execute mysql command.For demo we will create database and table and will insert data.
  • First check what databases we already have
  • show databases

  • We will create our own database lets say preparationforinterview
  • create database preparationforinterview;

    show databases

  • Now we will go inside preparationforinterview database and will create table say Employee
  • use preparationforinterview;


  • Now we will insert a row in Employee table

  • To exit from mysql shell type
  • quit

Visit Others Links

Docker Introduction
Docker Features
Docker Installation On Window
Docker Hello World Example On Window
Software Download In Docker Using command line
Software Search From Docker Hub Web Console
Docker Image Install from File System
Docker Volume Example
Installation Of Mysql in Docker With Example
Docker Frequently Used Commands
Top Docker Interview Question
© 2019