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:
-
I used the Fly CLI to create the PostgreSQL database named
db-app:flyctl postgres create -n db-app --autostart true --region cdg --vm-size shared-cpu-1x --initial-cluster-size 1 --volume-size 2 -
Next, I created a Spring Boot application named
example-appon Fly.io:flyctl apps create example-app -o org -
I attached the PostgreSQL database
db-appto the Spring Boot application:flyctl attach db-app -a example-app --database-name db --database-user user -
then I deployed it using a configuration file
fly.toml:flyctl deploy --config fly.toml -a example-app -ha=false --volume-initial-size 2fly.tomlconfiguration: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']
I consistently receive the following error:
java.net.UnknownHostException: db-app.flycast
I have:
-
Confirmed that the PostgreSQL database
db-appis created successfully on Fly.io. -
Verified DNS resolution for
db-app.flycastusingpingandnslookup, ensuring it resolves to the correct IP address. -
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. -
Verified that
application.propertiesorapplication.ymlin the Spring Boot application correctly points todb-app.flycastwith the appropriate port and credentials. -
Checked Fly.io logs (
flyctl logs -a example-app) for any connectivity issues or errors related to database access.
How can I resolve the UnknownHostException issue and ensuring successful deployment of my Spring Boot application with PostgreSQL on Fly.io?