Created by Kaushal Kishore
Email : kaushal.rahuljaiswal@gmail.com
Website : http://www.kaushalkishore.com
Step 1 : Clone the Docker-MySQL.git
Command: git clone https://github.com/kaushalkishorejaiswal/Docker-MySQL.git
Step 2 : Change the directory to the clone folder
Command: cd Docker-MySQL
Step 3 : Create the Docker Image
Command: sudo docker build -t ##NAME_OF_YOUR_DOCKER_IMAGE## .
Note : a). This command will be fired where the DockerFile will be placed b). ##NAME_OF_YOUR_DOCKER_IMAGE## : Replace it with your image name c). . : (.) Symbols shows that your Dockerfile is available on the same directory where you are running the command.
Step 4 : Create an MySQL Installed Container from the image
Command Syntax: sudo docker run --name [container name] -p [port to access (New Port):port exposed(original port)] -i -t [image name]
Command: sudo docker run --name ##NAME_OF_YOUR_DOCKER_CONTAINER## -d -p 3311:3306 ##NAME_OF_YOUR_DOCKER_IMAGE##
Example: sudo docker run --name MySQL5.5_Container -d -p 3311:3306 kaushal_mysql Here
- MySQL5.5_Container : Is the name of my container, which will be displayed on running of docker ps -a
- 3311 : Is the port where the docker container is running on host machine
- 3306 : Is the exposed port
- kaushal_mysql : Is the name of our docker image
Step 5 : Now you can access your MySQL container from your CLI.
Command: mysql -uroot -proot -h172.17.42.1 -P3311
- docker images : To list all the images of your docker
- docker ps : To list all the runing containers
- docker kill ##CONTAINER_NAME## : To kill the runing container
- docker rm ##CONTAINER_NAME## : To delete the container from the system.
- docker inspect ##CONTAINER_NAME## : To get all the information about the container.
- docker logs ##CONTAINER_NAME## : To get the logs of the container.
- docker ps -a: To get the listing of all the containers.
- docker start ##CONTAINER_NAME##: To start the exiting docker container.
- You can run multiple container using single image, but you will have to define a free port and the name for it.
- You can get the Gateway IP and other information of the docker container using the command docker inspect ##CONTAINER_NAME##
- You can get the container name using the command docker ps -a
- You can use any of the mysql client command inside the docker
- You can connect it from PHP using : mysql_connect('172.17.42.1:3311', 'root', 'root') - You will have to mention the port name here with IP.
- For changing the username and password modify the MYSQL_USER and MYSQL_PASS enviroment variables inside the Dockerfile
- You can also access your docker container from mysql-workbech and phpmyadmin interface