Skip to content

Instantly share code, notes, and snippets.

@initcron
Last active March 6, 2018 16:07
Show Gist options
  • Save initcron/78341235c41fa1eb43301f22d00edc4c to your computer and use it in GitHub Desktop.
Save initcron/78341235c41fa1eb43301f22d00edc4c to your computer and use it in GitHub Desktop.

Build Step

Clone Repository for Petclinic Application

git clone https://github.com/devopsdemoapps/spring-petclinic.git

Compile code using on demand process

docker container run --rm -v /absolute/path/to/spring-petclinic:/opt/spring-petclinic  schoolofdevops/maven mvn package -f /opt/spring-petclinic/pom.xml

whereas,

/absolute/path/to/spring-petclinic is the absolute path to the application directory cloned above. Change it as per your actual path on the system.

This should build the app and create a jarfile inside target/ directory of your application code.

Package Step

Create a Container with java image to package this app

docker container run -idt --name interim java:alpine sh

Copy over the build artifact jarfile

cd spring-petclinic 
docker container cp target/*.jar interim:/run/

Connect to container and validate

docker container exec -it interim sh

cd /run

java -jar spring-petclinic-1.5.1.jar

Commit container to an image

  • Exit from the container shell
  • Note container ID
     
  docker container commit interim  <docker_hub_id>/petclinic:v1

Push Image to registry

Before you push the image, you need to be logged in to the registry, with the docker hub id created earlier. Login using the following command,

docker login 

To push the image, first list it,

docker image ls

[Sample Output]

REPOSITORY                   TAG                 IMAGE ID            CREATED             SIZE
xyz/worker               v1              90cbeb6539df        18 minutes ago      194MB

To push the image,

docker push <docker_hub_id>/petclinic:v1

Testing Image

docker container run -idt --name pettest -p 8080:8080 <docker_hub_id>/petclinic:v1 java -jar /run/spring-petclinic-1.5.1.jar

docker ps 

docker logs  -f pettest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment