-
First cteated a demo spring boot project
-
Generate jar file
mvn clean package
-
create Dockerfile and write the necessary configuration
-
In locally running docker build docker image based on docker file
docker build -t image_tag_name .
-
Run docker image
docker run -p hostport:containport imagename
-
Run docker image Detach Mode
docker run -p hostport:containport -d imagename
Ex,docker run -p 8081:8081 -d imagename
-
To see logs
docker logs -f first_four_digit_of_container_ID
-
Login in Dockerhub
docker login
provide credentials -
docker tag spring_boot_docker_demo mohosin16103308/spring_boot_docker_demo:0.1.RELEASE
Note: spring_boot_docker_demo here will be image name
-
docker push springdockerlatest mohosin16103308/springdockerlatest:0.1.RELEASE
-
Docker pull
docker pull -p 4000:8080 mohosin16103308/springdockerlatest:0.1.release
Note: By default docker will try to pull from latest tag, As our tag name is 0.1.release. So we have to specify when we pull from docker hub.
- Run MySql
docker run -p 3307:3306 --name localhost -e MYSQL_ROOT_PASSWORD=mohosin -e MYSQL_DATABASE=blog_app -e MYSQL_USER=mohosin -e MYSQL_PASSWORD=mohosin -d mysql:latest
Note: here localhost is the custom of contain name that we can define as we want.
13) docker logs -f localhost
-
Login mysql in Docker
docker exec -it localhost bash
Note: localhost(container name) -
To login in terminal
mysql -u root -p
and provide necessary credentails
-
To see database
show databases;
, Here we can use other mysql commands.