Hi guys i am having trouble with deploying my ktor...
# ktor
b
Hi guys i am having trouble with deploying my ktor backend to render via Docker Neither port nor sslPort specified. Use command line options -port/-sslPort or configure connectors in application.conf I am getting this error.
Copy code
# 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 file
i am able to build the fat.jar but that is not running propperly
Althogh i am able to run the project manually like starting the Application.kt file and the api works fine and all
g
If you use configuration in a file you need to specify the conf file when starting the docker container
Copy code
ENTRYPOINT ["java","-jar","/app/ktor-docker-sample.jar", "-config=application.conf"]
where conf:
Copy code
ktor {
  deployment {
    port = 8585
  }
}
b
@gpopides
Copy code
ktor {
    deployment {
        port = 8080
        port = ${?PORT}
    }
    application {
        modules = [ com.travelKmp.ApplicationKt.module ]
    }
}
this is mu application.comf file
g
You need to pass it as a parameter to the entrypoint of your docker image so ktor can load it
b
@gpopides got it i will test but for testing i just created a new peoject with nothing in it and added this docker file
Copy code
# 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
Copy code
ktor {
  deployment {
    port = 8080
    port = ${?PORT}
  }
  application {
    modules = [com.example.ApplicationKt.module]
  }
}
this was my cong file but this project ran perfectly
g
You are not passing the
application.conf
to the entrypoint, can you try the following?
Copy code
# 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"]
b
@gpopides i got this error 1 warning found (use docker --debug to expand): - LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format (line 4) Dockerfile:26 -------------------- 24 | RUN mkdir /app 25 | COPY --from=build /home/gradle/src/build/libs/fat.jar /app/app.jar 26 | >>> COPY --from=build src/main/resources/application.conf application.conf 27 | ENTRYPOINT ["java","-jar","/app/app.jar", "-config=application.conf"] -------------------- ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref nr26inj9zw5sjjsmriekk672t:zeo18yx4wvqp0qhfk2kk9q7hy "/src/main/resources/application.conf": not found View build details: docker-desktop://dashboard/build/default/default/v1zx04981epa6c8ujtn83vx56
g
you need to specify the path of the application.conf so it can be copied. I cannot give you an exact path since i don't really know where you have the file. The idea is that you need to copy your conf file to the docker image you are building and then pass it as a parameter to the java command
b
the application.conf is in my resources but i am still getting the error
@gpopides also i have another wuestion that my other progect where i built a new peoject the docker file is the same as what i gave first without copying the application.conf that projhect throws no error and works fine
g
Copy code
# 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?
b
@gpopides already did not working i tried
Copy code
/home/src/main/resources/application.conf
/home/gradle/src/main/resources/application.conf
both
ok at last
Copy code
COPY --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)
g
i setup a new project and used the following docker file:
Copy code
# 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 too
b
did not work i think my problem is project specific but i am not able to understand https://github.com/PalankiBharat/Travel-Kmp-Backend
g
Looking at the project, you are missing the the
package
in all of your files. I believe this is the reason
b
okk but i dotn have any problem running locally
also my dir looks like this they all are in root dir the default project is also like this so what should i add in packjage
g
I noticed 2 things. For some reason (one of the dependencies) requires the
yaml
file to be present, so you need to add an
application.yaml
file
Copy code
ktor:
  application:
    modules:
      - com.example.ApplicationKt.module
  deployment:
    port: 8080
You also need to set the main class name in
build.gradle.kts
Copy code
application {
    mainClass = "com.example.ApplicationKt"
}
and also move everything under a package
com.example
and then change
application.conf
to
application.yaml
inside your dockerfile
image.png
b
how did you know that one dependency needs yaml file to be present? @gpopides
g
b
@gpopides yes the package was a major issue and i have changed to yaml file it is fixed. really thanks for the time and effort you gave to solve my problem