11. Docker – Implementation => CONTAINER LINK WITH MYSQL.

Docker – Implementation => CONTAINER LINK WITH MYSQL.



DOCKER PAGE :

https://hub.docker.com/_/mysql

 

00. docker pull mysql:5.7

01. docker images

02. docker run -p 3307:3306 --name=mysql_server -e MYSQL_ROOT_PASSWORD=root -e MYSQL_USER=root -e MYSQL_PASSWORD=root -d mysql:5.7 // this is woking.......................................

    docker run -p 3300:3306 --name mysql_server -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7  // this is woking.......................................

 

                                                OR

 

01. docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag

    docker run -p 3307:3306 --name=mysql_server -e MYSQL_ROOT_PASSWORD=root -e MYSQL_USER=root -e MYSQL_PASSWORD=root -d mysql:5.7 // this is woking.......................................

    docker run -p 3300:3306 --name mysql_server -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7  // this is woking.......................................

02. docker images // VIEW ALLIMAGES AND SEE WHETHER mysql IS IN THERE

03. docker ps -a // VIEW ALL CONAINER PROCESS- RUNNING OR NOT. SEE mysql CONTAINER UP OR NOT.IF IT IS NOT, THERE IS SOME ERROR TO FIXED.

04. docker exec -it id_of_container bin/bash -------- sql //EXAMPLE : docker exec -it 55b8232bfc82 bin/bash

05. mysql -u root -p root  // mysql -u root -p PRESS ENTER AND GIVE PASSWORD[IN MY EXAMPLE(according to 01) IT IS root]

06. docker logs  mysql // TO SEE MYSQL LOGS

06. docker exec -i mysql-docker mysql -uroot -proot demo < demo_data.sql //TO QUERY DATA TO DB FROM EXTERNAL SQL FILE.

PROJECT LINK WITH MY SQL

docker run -t --link mysql-demo:mysql -p 8088:8080 spring-demo-docker

docker run -t --link mysql_server:mysql -p 9093:8083 --name springboot_prj3_mysql_cont -d springboot_prj3_mysql_img // this is working.......................................

 

docker start cdb413245aa1ec1c7e9747650c88b8fa2c18b00023e257650ea87cefc126b9e9

 

GO INSIDE THE DOCKER CONTAINER

docker exec -it idofcontainer bin/bash -------- sql

mysql -u root -p demo

Then query can be executed.

 

 ----EXTRA NOTE

//working but containers are not running error - Error response from daemon: Container is not running

docker run -p 3300:3301 --name=mysql -env="MYSQL_ROOT_PASSWORD=root" -env="MYSQL_PASSWORD=root" -d mysql:5.7

docker run -d -p 3300:3301 --name=mysql -env="MYSQL_ROOT_PASSWORD=root" -env="MYSQL_PASSWORD=root" -env="MYSQL_DATABASE=test" mysql:5.7

 

//

docker ps -a = view all container process - running and not

 

 

docker-compose -f docker-compose.yml up

docker-compose -f docker-compose.yml down

Comments

Popular posts from this blog

02. Spring – Creating spring project clone it with GIT step by step.

02.What is MicroService?

06.Mongo DB - Query part 2 (Aggregation)