Construyendo Imagenes Docker con Spring Boot Build Image
spring-boot build packages, una forma rápida de crear tus imágenes docker sin Dockerfile
Table of contents
Seguramente hayan escuchado de Dockerfile para construir imágenes Docker, pero hoy me gustaría mostrarles una forma rápida de crear imágenes Docker para aplicaciones creadas con Spring Boot con solo ejecutar 1 comando.
Para esto tenemos un comando que nos proporciona el plugin spring-boot-maven-plugin
, también usado para construir los archivos jar de nuestras aplicaciones spring
boot.
Entorno
- maven
- docker
- mac book pro.
- java 11
Construyendo la Imagen Docker
Lo primero que tenemos que hacer es ir a la terminal y posicionarnos en la carpeta donde se encuentra nuestro archivo pom.xml, una vez estemos ahí ejecutamos el comando
mvn spring-boot:build-image
Deberíamos ver un resultado similar a este
[INFO] [creator] Paketo Executable JAR Buildpack 5.2.1
[INFO] [creator] https://github.com/paketo-buildpacks/executable-jar
[INFO] [creator] Class Path: Contributing to layer
[INFO] [creator] Writing env/CLASSPATH.delim
[INFO] [creator] Writing env/CLASSPATH.prepend
[INFO] [creator] Process types:
[INFO] [creator] executable-jar: java org.springframework.boot.loader.JarLauncher (direct)
[INFO] [creator] task: java org.springframework.boot.loader.JarLauncher (direct)
[INFO] [creator] web: java org.springframework.boot.loader.JarLauncher (direct)
[INFO] [creator]
[INFO] [creator] Paketo Spring Boot Buildpack 4.6.0
[INFO] [creator] https://github.com/paketo-buildpacks/spring-boot
[INFO] [creator] Creating slices from layers index
[INFO] [creator] dependencies
[INFO] [creator] spring-boot-loader
[INFO] [creator] snapshot-dependencies
[INFO] [creator] application
[INFO] [creator] Launch Helper: Contributing to layer
[INFO] [creator] Creating /layers/paketo-buildpacks_spring-boot/helper/exec.d/spring-cloud-bindings
[INFO] [creator] Spring Cloud Bindings 1.8.0: Contributing to layer
[INFO] [creator] Downloading from https://repo.spring.io/release/org/springframework/cloud/spring-cloud-bindings/1.8.0/spring-cloud-bindings-1.8.0.jar
[INFO] [creator] Verifying checksum
[INFO] [creator] Copying to /layers/paketo-buildpacks_spring-boot/spring-cloud-bindings
[INFO] [creator] Web Application Type: Contributing to layer
[INFO] [creator] Reactive web application detected
[INFO] [creator] Writing env.launch/BPL_JVM_THREAD_COUNT.default
[INFO] [creator] 4 application slices
[INFO] [creator] Image labels:
[INFO] [creator] org.opencontainers.image.title
[INFO] [creator] org.opencontainers.image.version
[INFO] [creator] org.springframework.boot.version
[INFO] [creator] ===> EXPORTING
[INFO] [creator] Adding layer 'paketo-buildpacks/ca-certificates:helper'
[INFO] [creator] Adding layer 'paketo-buildpacks/bellsoft-liberica:helper'
[INFO] [creator] Adding layer 'paketo-buildpacks/bellsoft-liberica:java-security-properties'
[INFO] [creator] Adding layer 'paketo-buildpacks/bellsoft-liberica:jre'
[INFO] [creator] Adding layer 'paketo-buildpacks/executable-jar:classpath'
[INFO] [creator] Adding layer 'paketo-buildpacks/spring-boot:helper'
[INFO] [creator] Adding layer 'paketo-buildpacks/spring-boot:spring-cloud-bindings'
[INFO] [creator] Adding layer 'paketo-buildpacks/spring-boot:web-application-type'
[INFO] [creator] Adding 5/5 app layer(s)
[INFO] [creator] Adding layer 'launcher'
[INFO] [creator] Adding layer 'config'
[INFO] [creator] Adding layer 'process-types'
[INFO] [creator] Adding label 'io.buildpacks.lifecycle.metadata'
[INFO] [creator] Adding label 'io.buildpacks.build.metadata'
[INFO] [creator] Adding label 'io.buildpacks.project.metadata'
[INFO] [creator] Adding label 'org.opencontainers.image.title'
[INFO] [creator] Adding label 'org.opencontainers.image.version'
[INFO] [creator] Adding label 'org.springframework.boot.version'
[INFO] [creator] Setting default process type 'web'
[INFO] [creator] Saving docker.io/library/lab-1:latest...
[INFO] [creator] *** Images (019302746a92):
[INFO] [creator] docker.io/library/lab-1:latest
[INFO]
[INFO] Successfully built image 'docker.io/library/lab-1:latest'
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 19.660 s
[INFO] Finished at: 2021-09-13T08:14:17-05:00
[INFO] ------------------------------------------------------------------------
Finalmente verificamos la imagen creada con el siguiente comando docker images
Podemos ver la imagen recién creada
lab-1 latest 019302746a92 41 years ago 263MB
paketobuildpacks/builder base 33f61a7d9dc3 41 years ago 779MB
hello-lab1 1.0.0-SNAPSHOT 5ca785c91f5d 41 years ago 263MB