How to Deploy a Spring Boot App (Java & Kotlin) Without a Dockerfile
Deploy a Spring Boot app (Java or Kotlin) with Maven or Gradle in one command: PORT binding, PostgreSQL settings injected for you and JVM memory tuning.
- Published
- Reading time
- 3 min
On this page
Key takeaways
- DockHosting builds an executable JAR from pom.xml or build.gradle (Maven 3.9+, Gradle 8.x) on Java 17 or 21: no Dockerfile needed.
- Bind the port with server.port=${PORT:8080}; attach PostgreSQL and the spring.datasource settings are injected as environment variables.
- Cap the heap with -XX:MaxRAMPercentage so the JVM fits the container, and expect slower starts: apps get up to 5 minutes.
Spring Boot apps are usually deployed with a hand-written Dockerfile, a JVM base image and a lot of tuning. You can skip most of that: give the platform your Maven or Gradle project and it builds the JAR for you.
What happens on deploy
pom.xmlorbuild.gradlemarks the project as Java/Kotlin.- Maven 3.9+ or Gradle 8.x builds an executable JAR.
- The JAR runs on Eclipse Temurin, Java 17 or 21 LTS, with a tuned garbage collector.
- You get
https://<project>.dockhosting.cloudwith automatic HTTPS.
Scheduled jobs (@Scheduled, Quartz) and background workers run alongside the web server.
1. Listen on the platform's port
# src/main/resources/application.properties
server.port=${PORT:8080}
server.shutdown=graceful${PORT:8080} uses the PORT variable in production and 8080 locally. Graceful shutdown lets in-flight requests finish during a zero-downtime deploy.
2. Add PostgreSQL
Create a managed PostgreSQL database in the dashboard and attach it to the project. The spring.datasource properties are injected as environment variables, which Spring Boot maps onto its configuration automatically, so you don't hard-code a URL, user or password.
<!-- pom.xml -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>For schema changes, use Flyway or Liquibase. Both run at startup, before the app takes traffic.
3. Fit the JVM into the container
The JVM sizes its heap from the container's memory, but leaves little room for everything else. Set an explicit share:
JAVA_TOOL_OPTIONS=-XX:MaxRAMPercentage=75Add it as an environment variable. Rough guide:
| Plan | Memory | Comfortable for |
|---|---|---|
| Free | 512 MB (shared with its database) | A small API |
| Hobby | 1 GB | Most single services |
| Pro | Up to 2 GB per app | Larger apps, several services |
| Team | Up to 4 GB per app | Heavy workloads |
4. Deploy
curl -fsSL https://cli.dockhosting.dev/install.sh | sh # Windows: irm https://cli.dockhosting.dev/install.ps1 | iex
dock login
dock deployFollow the startup with dock logs. Spring Boot can take a while to start on a small container, so DockHosting gives apps up to 5 minutes to start listening before a start is marked as failed.
5. Faster startup
- Trim starters you don't use. Each one adds auto-configuration work at boot.
- Lazy initialization (
spring.main.lazy-initialization=true) defers beans until first use, at the cost of a slower first request. - Expose a health endpoint with
spring-boot-starter-actuator(/actuator/health) so you can tell "starting" from "broken".
Want full control of the image instead? Add a Dockerfile and it's built as-is. See deploying any Docker container.
Frequently asked questions
Do I need a Dockerfile for Spring Boot?
No. DockHosting detects pom.xml or build.gradle, builds an executable JAR with Maven or Gradle and runs it on Eclipse Temurin (Java 17 or 21). If a Dockerfile is present, it's built from that instead.
Is Kotlin supported?
Yes. Kotlin Spring Boot projects build the same way, with Gradle or Maven.
Can a Spring Boot app run on the Free plan?
Yes. The Free plan covers a Spring Boot service with one database. Keep the heap small, and remember the app sleeps after 1 hour idle; the JVM's startup time makes the first request after a sleep slower. Hobby ($4/month) is always on.
- Spring Boot
- Java
- Kotlin
- PostgreSQL
- Tutorial
Written by Doughmi ILYAS
Doughmi builds DockHosting, the developer-first platform behind dock deploy: the build system, the managed databases and the dashboard. On this blog: guides to shipping apps without running servers, written with the commands the platform actually ships.
