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