bk9735732777
07/03/2025, 6:33 AM# Stage 1: Cache Gradle dependencies
FROM gradle:latest AS cache
RUN mkdir -p /home/gradle/cache_home
ENV GRADLE_USER_HOME=/home/gradle/cache_home
COPY build.gradle.* gradle.properties /home/gradle/app/
COPY gradle /home/gradle/app/gradle
WORKDIR /home/gradle/app
RUN gradle clean build -i --stacktrace
# Stage 2: Build Application
FROM gradle:latest AS build
COPY --from=cache /home/gradle/cache_home /home/gradle/.gradle
COPY --chown=gradle:gradle . /home/gradle/src
WORKDIR /home/gradle/src
# Build the fat JAR, Gradle also supports shadow
# and boot JAR by default.
RUN gradle buildFatJar --no-daemon
# Stage 3: Create the Runtime Image
FROM amazoncorretto:22 AS runtime
EXPOSE 8080
RUN mkdir /app
COPY --from=build /home/gradle/src/build/libs/*.jar /app/ktor-docker-sample.jar
ENTRYPOINT ["java","-jar","/app/ktor-docker-sample.jar"]
This is my docker filebk9735732777
07/03/2025, 6:33 AMbk9735732777
07/03/2025, 6:35 AMgpopides
07/03/2025, 6:54 AMENTRYPOINT ["java","-jar","/app/ktor-docker-sample.jar", "-config=application.conf"]
where conf:
ktor {
deployment {
port = 8585
}
}
bk9735732777
07/03/2025, 7:06 AMktor {
deployment {
port = 8080
port = ${?PORT}
}
application {
modules = [ com.travelKmp.ApplicationKt.module ]
}
}
this is mu application.comf filegpopides
07/03/2025, 7:07 AMbk9735732777
07/03/2025, 7:12 AM# Stage 1: Cache Gradle dependencies
FROM gradle:latest AS cache
RUN mkdir -p /home/gradle/cache_home
ENV GRADLE_USER_HOME /home/gradle/cache_home
COPY build.gradle.* gradle.properties /home/gradle/app/
COPY gradle /home/gradle/app/gradle
WORKDIR /home/gradle/app
RUN gradle clean build -i --stacktrace
# Stage 2: Build Application
FROM gradle:latest AS build
COPY --from=cache /home/gradle/cache_home /home/gradle/.gradle
COPY . /usr/src/app/
WORKDIR /usr/src/app
COPY --chown=gradle:gradle . /home/gradle/src
WORKDIR /home/gradle/src
# Build the fat JAR, Gradle also supports shadow
# and boot JAR by default.
RUN gradle buildFatJar --no-daemon
# Stage 3: Create the Runtime Image
FROM amazoncorretto:22 AS runtime
EXPOSE 8080
RUN mkdir /app
COPY --from=build /home/gradle/src/build/libs/fat.jar /app/app.jar
ENTRYPOINT ["java","-jar","/app/app.jar"]
and
ktor {
deployment {
port = 8080
port = ${?PORT}
}
application {
modules = [com.example.ApplicationKt.module]
}
}
this was my cong file but this project ran perfectlygpopides
07/03/2025, 7:14 AMapplication.conf
to the entrypoint,
can you try the following?
# Stage 1: Cache Gradle dependencies
FROM gradle:latest AS cache
RUN mkdir -p /home/gradle/cache_home
ENV GRADLE_USER_HOME /home/gradle/cache_home
COPY build.gradle.* gradle.properties /home/gradle/app/
COPY gradle /home/gradle/app/gradle
WORKDIR /home/gradle/app
RUN gradle clean build -i --stacktrace
# Stage 2: Build Application
FROM gradle:latest AS build
COPY --from=cache /home/gradle/cache_home /home/gradle/.gradle
COPY . /usr/src/app/
WORKDIR /usr/src/app
COPY --chown=gradle:gradle . /home/gradle/src
WORKDIR /home/gradle/src
# Build the fat JAR, Gradle also supports shadow
# and boot JAR by default.
RUN gradle buildFatJar --no-daemon
# Stage 3: Create the Runtime Image
FROM amazoncorretto:22 AS runtime
EXPOSE 8080
RUN mkdir /app
COPY --from=build /home/gradle/src/build/libs/fat.jar /app/app.jar
COPY --from=build src/main/resources/application.conf application.conf
ENTRYPOINT ["java","-jar","/app/app.jar", "-config=application.conf"]
bk9735732777
07/03/2025, 7:24 AMgpopides
07/03/2025, 7:26 AMbk9735732777
07/03/2025, 7:31 AMbk9735732777
07/03/2025, 7:34 AMgpopides
07/03/2025, 7:37 AM# Stage 1: Cache Gradle dependencies
FROM gradle:latest AS cache
RUN mkdir -p /home/gradle/cache_home
ENV GRADLE_USER_HOME /home/gradle/cache_home
COPY build.gradle.* gradle.properties /home/gradle/app/
COPY gradle /home/gradle/app/gradle
WORKDIR /home/gradle/app
RUN gradle clean build -i --stacktrace
# Stage 2: Build Application
FROM gradle:latest AS build
COPY --from=cache /home/gradle/cache_home /home/gradle/.gradle
COPY . /usr/src/app/
WORKDIR /usr/src/app
COPY --chown=gradle:gradle . /home/gradle/src
WORKDIR /home/gradle/src
# Build the fat JAR, Gradle also supports shadow
# and boot JAR by default.
RUN gradle buildFatJar --no-daemon
# Stage 3: Create the Runtime Image
FROM amazoncorretto:22 AS runtime
EXPOSE 8080
RUN mkdir /app
COPY --from=build /home/gradle/src/build/libs/fat.jar /app/app.jar
COPY --from=build /home/gradle/src/main/resources/application.conf application.conf
ENTRYPOINT ["java","-jar","/app/app.jar", "-config=application.conf"]
can you try with this dockerfile?bk9735732777
07/03/2025, 7:39 AM/home/src/main/resources/application.conf
/home/gradle/src/main/resources/application.conf
bothbk9735732777
07/03/2025, 7:40 AMCOPY --from=build /home/gradle/src/build/resources/main/application.conf application.conf
this worked but still i have the error
Exception in thread "main" java.lang.IllegalArgumentException: Neither port nor sslPort specified. Use command line options -port/-sslPort or configure connectors in application.conf
2025-07-03T073936.919776256Z at io.ktor.server.engine.CommandLineKt.CommandLineConfig(CommandLine.kt:74)
2025-07-03T073936.919781631Z at io.ktor.server.netty.EngineMain.createServer(EngineMain.kt:37)
2025-07-03T073936.919782881Z at io.ktor.server.netty.EngineMain.main(EngineMain.kt:24)
2025-07-03T073936.919926090Z at com.travelKmp.ApplicationKt.main(Application.kt:5)gpopides
07/03/2025, 8:00 AM# Stage 1: Cache Gradle dependencies
FROM gradle:latest AS cache
RUN mkdir -p /home/gradle/cache_home
ENV GRADLE_USER_HOME /home/gradle/cache_home
COPY build.gradle.* gradle.properties /home/gradle/app/
COPY gradle /home/gradle/app/gradle
WORKDIR /home/gradle/app
RUN gradle build -i --stacktrace
# Stage 2: Build Application
FROM gradle:latest AS build
COPY --from=cache /home/gradle/cache_home /home/gradle/.gradle
COPY . /usr/src/app/
WORKDIR /usr/src/app
COPY --chown=gradle:gradle . /home/gradle/src
WORKDIR /home/gradle/src
# Build the fat JAR, Gradle also supports shadow
# and boot JAR by default.
RUN gradle buildFatJar --no-daemon
# Stage 3: Create the Runtime Image
FROM eclipse-temurin:23-jre AS runtime
EXPOSE 8080
RUN mkdir /app
COPY --from=build /home/gradle/src/build/libs/ktor-sample-all.jar /app/app.jar
COPY --from=build /usr/src/app/src/main/resources/application.yaml application.yaml
ENTRYPOINT ["java","-jar","/app/app.jar", "-config=application.yaml"]
and got it running.
If you change application.yaml
to application.conf
and ktor-sample-all.jar
to fat.jar
it should work
I also used temurin instead of correto so you can change that toobk9735732777
07/03/2025, 9:04 AMgpopides
07/03/2025, 9:44 AMpackage
in all of your files. I believe this is the reasonbk9735732777
07/03/2025, 10:49 AMbk9735732777
07/03/2025, 10:50 AMgpopides
07/03/2025, 11:55 AMyaml
file to be present, so you need to add an application.yaml
file
ktor:
application:
modules:
- com.example.ApplicationKt.module
deployment:
port: 8080
You also need to set the main class name in build.gradle.kts
application {
mainClass = "com.example.ApplicationKt"
}
and also move everything under a package com.example
and then change application.conf
to application.yaml
inside your dockerfilegpopides
07/03/2025, 11:56 AMbk9735732777
07/03/2025, 1:52 PMgpopides
07/03/2025, 1:57 PMbk9735732777
07/03/2025, 4:06 PM