git clone https://github.com/devopsdemoapps/spring-petclinic.git
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.
docker container run -idt --name interim java:alpine sh
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
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
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