https://kotlinlang.org logo
Title
s

Solomon Tolu Samuel

08/07/2021, 8:43 PM
Hello guys. I have been trying to build a Docker image for my ktor server application and i keep on getting an error. This is the Docker and the .yml file:
FROM openjdk:13 AS builder
RUN java --version
RUN mkdir /application
WORKDIR /application
COPY ./ ./
RUN ./gradlew clean build
RUN ls -al build/libs/
...
version: "3"
services:
  myapp:
    build: .
And this is the error i keep getting:
ERROR [6/7] RUN ./gradlew clean build                                                                                                                     1.9s
------
 > [6/7] RUN ./gradlew clean build:
#10 1.339 /bin/sh: ./gradlew: No such file or directory
------
executor failed running [/bin/sh -c ./gradlew clean build]: exit code: 127
ERROR: Service 'myapp' failed to build : Build failed
After trying lots of solutions, i decided to use another approach:
FROM openjdk:8-jre-alpine
ENV APPLICATION_USER ktor
RUN adduser -D -g '' $APPLICATION_USER
RUN mkdir /app
RUN chown -R $APPLICATION_USER /app
USER $APPLICATION_USER
COPY ./build/libs/app.jar /app/app.jar
WORKDIR /app
CMD ["java","-server","-XX:+UnlockExperimentalVMOptions","-XX:+UseCGroupMemoryLimitForHeap","-XX:InitialRAMFraction=2","-XX:MinRAMFraction=2","-XX:MaxRAMFraction=2","-XX:+UseG1GC","-XX:MaxGCPauseMillis=100","-XX:+UseStringDeduplication","-jar","app.jar"]
And i also got a similar error:
ERROR [5/6] COPY ./build/libs/app.jar /app/app.jar                                                                                                        0.0s
------
 > [5/6] COPY ./build/libs/app.jar /app/app.jar:
------
failed to compute cache key: "/build/libs/app.jar" not found: not found
h

hfhbd

08/07/2021, 8:59 PM
FROM openjdk:13 AS builder
RUN java --version
RUN mkdir /application
WORKDIR /application
COPY . .     <- use .
RUN ./gradlew clean build
RUN ls -al build/libs/
Did you add the
.gradlew
to
.dockerignore
? If you want to use a
builder
you have to include the consumer too 😄 Just check your paths with
ls
. Guess: in 2nd COPY:
COPY ./build/libs/app.jar /app/app.jar
should it not be
COPY build/libs/app.jar /app/app.jar
?
s

Solomon Tolu Samuel

08/07/2021, 9:53 PM
Hey, i think i forgot to mention that i am a docker novice.. but i tried both your suggestions and non seems to work... i am still getting the same errors with both approach
d

dave08

08/08/2021, 2:14 AM
Try google jib, it'll make docker images for you without all the manual configs