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]

Configuración de Profiles para Spring-Boot

Proceso para crear profiles para un proyecto Spring-boot

  1. Configurar en el pom.xml los perfiles deseados, por ejemplo, a continuación se configura dos profiles para dev y prod
    
        <profiles>
    	<profile>
    		<id>dev</id>
    		<properties>
    			<activatedProperties>dev</activatedProperties>
    		</properties>
    		<activation>
    			<activeByDefault>true</activeByDefault>
    		</activation>
    	</profile>
    
    	<profile>
    		<id>prod</id>
    		<properties>
    			<activatedProperties>prod</activatedProperties>
    		</properties>
    	</profile>
        </profiles>
        
  2. Configurar los recursos que se van a cargar con el profile activo
    
         <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
    
            <resources>
                <resource>
                    <directory>src/main/resources</directory>
                    <filtering>true</filtering>
                </resource>
            </resources>
    
        </build>
        
  3. Configurar en el archivo application.properties el profile que se va a configurar de forma dinámica
    
        #SPRING PROFILES
    	spring.profiles.active=@activatedProperties@
    
  4. Para generar el jar con un profile específico se puede ejecutar el siguiente comando con la bandera -P<nombreProfile>
     mvn clean install -Pprod

Fuentes

Comentarios

Entradas populares de este blog

Create a docker image from a spring boot project

Comandos docker

Kubernetes -Tipos de objetos