This is a simple Spring Boot application used for demonstarting intergration with Docker. This also includes a few configurations to show deployment on Docker Swarm.
Following are a few aspects being demonstrated:
- Building Docker image using Dockerfile
- Building Docker image using Maven
- Basic deployment using Docker and invocation of health-check Rest API endpoint
- Deployment using Docker Compose with 3 replicas
- Deployment using Docker Compose with 3 replicas and visualizer
- JDK 8
- Docker
This application was tested on the following:
- OS : Ubuntu 18.04 LTS
- Docker: 18.09.3 (community)
-
Clone the repo to ~/demo directory
- mkdir ~/demo
- cd ~/demo
- git clone https://github.com/bijeshos/spring-boot-with-docker-demo.git
-
Change directory to project root
- $ cd ~/demo/spring-boot-with-docker-demo
- Perform Maven Build/Package
- $ mvn package -f pom.xml
-
Check locally available docker images
- $ docker images
-
Check all containers
- $ docker ps -a
-
Remove any unwanted containers (by specifyig respective container id)
- $ docker rm <container-id>
-
Remove any unwanted docker images (by specifying respective image id)
- $ docker rmi <image-id>
-
Build a docker image
- $ docker build --tag bijeshos/spring-boot-with-docker-demo:0.1 .
-
Run the docker image
- $ docker run -p 8080:8080 --name spring-boot-with-docker-demo bijeshos/spring-boot-with-docker-demo:0.1
-
Verify that health-check Rest API endpoint is accessible
-
Remove container
- $ docker rm <container-id>
-
Remove docker image
- $ docker rmi <image-id>
-
Initialize Docker Swam cluster
- $ docker swarm init
-
Deploy using Docker compose file
- $ docker stack deploy -c docker-compose-01-basic.yml spring-boot-with-docker-demo-stk
-
Check Docker Stack
- $ docker stack ls
- $ docker stack ps spring-boot-with-docker-demo-stk
-
Check Docker Services
- $ docker service ls
- $ docker service ps spring-boot-with-docker-demo-stk_web
-
Verify that health-check Rest API endpoint is accessible
-
Deploy using Docker compose file
- $ docker stack deploy -c docker-compose-02-with-visualizer spring-boot-with-docker-demo-stk
-
Check the visualize at:
-
Remove docker stack
- $ docker stack rm spring-boot-with-docker-demo-stk
-
Shutdown Docker Swarm Cluster
- $ docker swarm leave --force
- Docker commands can be executed directly as current user
- If this is not correctly setup, prefix sudo with above mentioned docker commands (On Debian machines)
- Integration with Kubernetes