Create a docker image from a spring boot project


In order to create a docker image from a spring boot project, First, your pom.xml has to be configured.

<build>
	<plugins>
		<plugin>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-maven-plugin</artifactId>
			<configuration>
				<!-- Cofiguration for creating a docker image -->
				<image>
					<name>chamow01/${project.artifactId}</name>
				</image>
			</configuration>
		</plugin>
	</plugins>
</build>
Then, the next maven command needs to be applied, so spring boot uses paketo-buildpacks in order to create a docker image based on you Java code

mvn spring-boot:build-image

...
[INFO]  > Running creator
[INFO]     [creator]     ===> DETECTING
[INFO]     [creator]     6 of 24 buildpacks participating
[INFO]     [creator]     paketo-buildpacks/ca-certificates   3.2.0
[INFO]     [creator]     paketo-buildpacks/bellsoft-liberica 9.3.2
[INFO]     [creator]     paketo-buildpacks/syft              1.10.1
[INFO]     [creator]     paketo-buildpacks/executable-jar    6.2.1
[INFO]     [creator]     paketo-buildpacks/dist-zip          5.2.1
[INFO]     [creator]     paketo-buildpacks/spring-boot       5.9.0
[INFO]     [creator]     ===> ANALYZING
[INFO]     [creator]     Previous image with name "docker.io/chamow01/diamonbank-loans:latest" not found
[INFO]     [creator]     ===> RESTORING
[INFO]     [creator]     ===> BUILDING
...

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 02:14 min
[INFO] Finished at: 2022-04-27T11:59:03-05:00
[INFO] Final Memory: 45M/759M
[INFO] ------------------------------------------------------------------------


Finally, the new docker image, can be checked using the command: docker images

$ docker images
REPOSITORY                           TAG        IMAGE ID       CREATED         SIZE
chamow01/diamonbank-loans            latest     76c9c266cd87   42 years ago    250MB

Docs

Comentarios

Entradas populares de este blog

Comandos docker

Kubernetes -Tipos de objetos