Search code examples
dockerkotlingrpcprotoc

Can't build docker container for Kotlin + gRPC project


Every time I try to build the application docker I get the following error:

java.io.IOException: Cannot run program "/home/gradle/.gradle/caches/modules-2/files-2.1/com.google.protobuf/protoc/3.20.3/898c37cfe230a987c908cff24f04a58d320578f1/protoc-3.20.3-linux-x86_64.exe": error=2, No such file or directory

I have tried to download and unzip the protoc in my dockerfile through the following command before building:

RUN curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v3.20.3/protoc-3.20.3-linux-x86_64.zip
RUN unzip -q protoc-3.20.3-linux-x86_64.zip

and the error stills.

The protobuf section in my "build.gradle" file is like this:

protobuf {
    protoc {
        artifact = "com.google.protobuf:protoc:3.20.3"
    }
    plugins {
        id("grpc") {
            artifact = "io.grpc:protoc-gen-grpc-java:1.46.0"
        }
        id("grpckt") {
            artifact = "io.grpc:protoc-gen-grpc-kotlin:0.2.0:jdk7@jar"
        }
    }
    generateProtoTasks {
        ofSourceSet("main").forEach {
            it.plugins {
                // Apply the "grpc" plugin whose spec is defined above, without options.
                id("grpc")
                id("grpckt")
            }
        }
    }
}

Solution

  • As I could find in this github issue I could solve it by adding the gcompact package into the Dockerfile prior to the building step.

    Now my Dockerfile is as follow:

    FROM gradle:7.5.1-jdk18-alpine AS build
    USER root
    
    WORKDIR /data
    COPY . /data
    
    RUN apk add gcompat
    RUN gradle assemble --no-daemon
    .
    .
    .