/Dockerize-Spring-Boot-Project

Dockerize Spring Boot Project and push it Docker Hub

Primary LanguageJava

In this project demonstate how we can dockerize and push our docker image in docker repository

Setps

  1. First cteated a demo spring boot project

  2. Generate jar file mvn clean package

  3. create Dockerfile and write the necessary configuration

  4. In locally running docker build docker image based on docker file docker build -t image_tag_name .

  5. Run docker image docker run -p hostport:containport imagename

  6. Run docker image Detach Mode docker run -p hostport:containport -d imagename Ex, docker run -p 8081:8081 -d imagename

  7. To see logs docker logs -f first_four_digit_of_container_ID

  8. Login in Dockerhub docker login provide credentials

  9. docker tag spring_boot_docker_demo mohosin16103308/spring_boot_docker_demo:0.1.RELEASE

Note: spring_boot_docker_demo here will be image name

  1. docker push springdockerlatest mohosin16103308/springdockerlatest:0.1.RELEASE

  2. 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.

  1. 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

  1. Login mysql in Docker docker exec -it localhost bash Note: localhost(container name)

  2. To login in terminal mysql -u root -p

    and provide necessary credentails

  3. To see database show databases; , Here we can use other mysql commands.