skip to Main Content

Trying to build an Image of loans application with BuildPacks approach, getting this below error


pom.xml :

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.3.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>loans</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>loans</name>
    <description>Microservice loans project</description>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
            <version>2.5.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>3.3.1</version>
                <configuration>
                    <image>
                        <name>kartik536/${project.artifactId}:v1</name>
                    </image>
                    <pullPolicy>IF_NOT_PRESENT</pullPolicy>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

WSL 2 configured in my machine, But in Docker desktop settings->Resources->WSL integration showing "You don’t have any WSL 2 distros installed. Please convert a WSL 1 distro to WSL 2, or install a new distro and it will appear here."

[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 13.67 s -- in com.example.loans.LoansApplicationTests
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- jar:3.4.2:jar (default-jar) @ loans ---
[INFO]
[INFO] --- spring-boot:3.3.1:repackage (repackage) @ loans ---
[INFO] Replacing main artifact C:Kartik_WorkspaceDockerProjectloanstargetloans-0.0.1-SNAPSHOT.jar with repackaged archive, adding nested dependencies in BOOT-INF/.
[INFO] The original artifact has been renamed to C:Kartik_WorkspaceDockerProjectloanstargetloans-0.0.1-SNAPSHOT.jar.original
[INFO]
[INFO] <<< spring-boot:3.3.1:build-image (default-cli) < package @ loans <<<
[INFO]
[INFO]
[INFO] --- spring-boot:3.3.1:build-image (default-cli) @ loans ---
[WARNING]  Parameter 'pullPolicy' (user property 'spring-boot.build-image.pullPolicy') is read-only, must not be used in configuration
[INFO] Building image 'docker.io/kartik536/loans:v1'
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  21.510 s
[INFO] Finished at: 2024-06-27T12:01:31+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:3.3.1:build-image (default-cli) on project loans: Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:3.3.1:build-image failed: Illegal char <:> at index 5: npipe:////./pipe/dockerDesktopLinuxEngine -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.

2

Answers


  1. So I was going through the same error and what I realized is that you have to create a new Dockerfile for the service .

    And the content of the file should be like this

    LABEL maintainer="arindam"
    WORKDIR /app
    ADD target/user-service-0.0.1-SNAPSHOT.jar /app/jar
    #ENV SPRING_DATASOURCE_URL: jdbc:mysql://mysql:3309/userdb?createDatabaseIfNotExist=true
    #ENV SPRING_DATASOURCE_USERNAME: root
    #ENV SPRING_DATASOURCE_PASSWORD: admin
    EXPOSE 4000
    ENTRYPOINT ["java",  "-jar" , "jar" , "app" , "exec"]```
    
    modify according to your needs
    
    but this has to be there inside the src  folder and after creating it run the command as
    
    `docker build -t bro-service-name:1 .(dot bro)`
    
    It will create the contianer of the image and then you can run the container
    
    Login or Signup to reply.
  2. Had similar issue:
    The solution is present in the below link
    https://github.com/spring-projects/spring-boot/issues/41199

    update your pom.xml plugin as below.

    <plugin>    
            <groupId>org.springframework.boot</groupId> 
            <artifactId>spring-boot-maven-plugin</artifactId>   
            <configuration>     
                <docker>            
                    <host>//./pipe/dockerDesktopLinuxEngine</host>      
                </docker>   
            </configuration>
        </plugin>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search