Docker & Spring Boot
My first upload to the containerized platform Goodbye to the server-based deployments. Feels good and well managed and can be distributed effortlessly.
When I executed my first http://localhost:9000/docker new journey to the containerization started.
I downloaded Docker and installed it in my local machine and created a free account in docker hub (https://hub.docker.com/).
Log in to the docker with the docker hub credentials (Right-click on the docker desktop and click sign in)
Here goes my sample project set up
Created a spring boot application using https://start.spring.io/ with spring-boot-starter-web dependency.
Created one controller to test the application
The key part of the docker containerization is the creation of Docker file
note*: Where 'D' should be capital and no extension is required.
and the file content is
FROM java:8 -> from java8 image
ADD target/springdocker.jar springdocker.jar -> our target jar naming
ENTRYPOINT ["java","-jar","springdocker.jar"] ->to execute the jar
Just a 3 line of statements to make application live.👏
Login to docker with the credentials that registered while creating the account.
then I executed the command docker build -t sudeep1987dk/springdocker .
where sudeep1987dk is the dockerId, at the end. (dot) is mandatory if we are running from the same directory of the docker file which will include all the files to the container.
All the 3 steps executed what we described in the Dockerfile.
To run this application hit the command like
docker run -p 9000:9000 sudeep1987dk/springdocker
first 9000 after -p (Port) is the docker port and the second 9000 is opening the port in the Operating System.
Tes the URL:http://localhost:9000/docker
Check the docker image by executing docker image ls
Finally pushing the docker image to the docker hub.
docker image push sudeep1987dk/springdocker
And it is successfully pushed in the docker hub.
to stop docker once it is done execute the command: docker container stop $(docker container list -q)
Useful docker commands
docker ps : will list running docker with container id
docker ps -a : will list all the docker images with history and current state
docker start 407751133d09: Start docker with docker id
docker stop 407751133d09: Stop docker with docker id
docker run : is an aggregate command (docker pull + docker start)
docker logs 407751133d09 : to get the logs or docker logs musing_lederberg (instead of container id , the name also used to get the logs)
docker exec -it 407751133d09 /bin/bash : When that application is running it helps us to find the configuration and deployment directories
docker container stop $(docker ps -a -q) : To stop all the live container.
docker rm $(docker ps -a -q) : To remove all the stopped containers.
Where '-it' opens an interactive terminal
exit is the command to exit from the interactive terminal