Docker and Spring Boot on Windows 10 Home
This is my first blog post so please be gentle ๐
I recently attended the Belfast Java User Group Docker & Spring Boot in Practice talk by Hudson Mendes slides here.
I recently attended the Belfast Java User Group Docker & Spring Boot in Practice talk by Hudson Mendes slides here.
I was going through some of the examples on a windows 10
home machine and here are some notes that might be useful to someone. Note the
instructions will likely be different on a different OS.
From an IDE e.g. Spring tool suite – create a workspace
Download and install docker toolbox (community version
doesn’t work on Windows 10 home)
Connect to github https://github.com/hudsonmendes/belfastjug-sample-2
Switch to branch dockerfile in Spring tool suite git
repository view
Copy files from HOME\git\hudsonmendes\belfastjug-sample-2 to
workspace directory – note for dockerfile branch the folder must be called “api-example” that has build.gradle etc. in it.
From docker quick start terminal – cd to api-example
directory
run “./gradlew eclipse” – this generates the eclipse files
Import existing project into spring tool suite if you want
to view files etc. The main files to look at are ApiExampleApplication.java (the Spring Boot application), build.gradle and Dockerfile.
From the same terminal, run “./gradlew bootRun” – this runs the sprint boot
application normally (not in docker)
Browse to http://localhost:8080/meetups/belfastjug/live_now
should get a “YES!”
CTRL-C to kill the app – confirm web link above no longer
works
Run “./gradlew build” – this builds the
“api-example-0.0.1-SNAPSHOT.jar” file in the build/libs folder
Run “docker build -t hudsonmendes/api-example .” – this
builds the docker image
Run “docker images” – this should show the image
Run “docker run -p 8080:8080 hudsonmendes/api-example” –
this runs the app in docker
There’s an issue with port forwarding in windows. Run
“docker-machine ip default” take a note of the IP address returned e.g.
192.168.99.100
Browse to Belfast JUG page on IP address from above e.g. http://192.168.99.100:8080/meetups/belfastjug/live_now
should get a “YES!”
Run “docker ps” to view running images
Run “docker login” – enter your docker hub username and
password (create one if you don’t have one)
Run e.g. “docker tag hudsonmendes/api-example
USERNAME/api-example:0.1” to tag your image with your username and version
Run e.g. “docker push USERNAME/api-example:0.1” to push your
image to docker hub
Browse to https://hub.docker.com/
to check the image is there
Run “docker stop CONTAINER_ID” to stop an image
Run “docker rmi –f IMAGE_ID” to remove an image
Comments
Post a Comment