I’m trying to deploy a Spring Boot application with a PostgreSQL database on Fly.io, but I keep encountering the UnknownHostException: db-app.flycast
error. Here’s the process I’ve followed:
-
Create PostgreSQL Database on Fly.io:
I used the Flyctl CLI to create the PostgreSQL database nameddb-app
:flyctl postgres create -n db-app
-
Create Spring Boot Application:
Next, I created a Spring Boot application namedexample-app
on Fly.io:flyctl apps create example-app
-
Attach PostgreSQL Database:
I attached the PostgreSQL databasedb-app
to the Spring Boot application using a configuration filefly.toml
:flyctl attach db-app --config fly.toml -a example-app
fly.toml Configuration:
kill_signal = "SIGINT"
kill_timeout = 5
swap_size_mb = 1024
[build]
dockerfile = "../docker/Dockerfile.app"
[http_service]
internal_port = 8080
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
processes = ['app']
Error Encountered:
I consistently receive the following error:
java.net.UnknownHostException: db-app.flycast
Troubleshooting Steps Taken:
-
Checked PostgreSQL Creation: Confirmed that the PostgreSQL database
db-app
is created successfully on Fly.io. -
DNS Resolution: Verified DNS resolution for
db-app.flycast
usingping
andnslookup
, ensuring it resolves to the correct IP address. -
Fly.io Networking Setup: Ensured that both the Spring Boot application and PostgreSQL database (
db-app
) are within the same Fly.io organization and region, and reviewed network policies. -
Spring Boot Application Configuration: Verified that
application.properties
orapplication.yml
in the Spring Boot application correctly points todb-app.flycast
with the appropriate port and credentials. -
Fly.io Service Logs: Checked Fly.io logs (
flyctl logs -a example-app
) for any connectivity issues or errors related to database access.
Request for Assistance:
I’m seeking guidance on resolving the UnknownHostException
issue and ensuring successful deployment of my Spring Boot application with PostgreSQL on Fly.io. Any insights or suggestions would be greatly appreciated.