Building the image

To build the Docker image with our Spring Boot artifact, run this command:

$ mvn clean package docker:build

The clean tells Maven to delete the target directory. Maven will always compile your classes with the package command. It is very important to run the package command with the docker:build command. You'll encounter errors if you try to run these in two separate steps. While the Docker image is building, you will see the following output in the console:

The ID of a new image will be presented in the console output. If you wonder how the automatically generated Dockerfile looks the same as, you will find it in the

Get Docker and Kubernetes for Java Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.