job "postgres-nomad-demo" {
datacenters = ["dc1"]
group "db" {
network {
port "db" {
static = 5432 # Static port mapping for 'db' service
}
}
task "server" {
driver = "docker"
config {
image = "hashicorp/postgres-nomad-demo:latest"
ports = ["db"] # Reference the 'db' port label
}
service {
name = "database"
port = "db" # Use the 'db' port label for service
provider = "nomad"
# Health check configuration inside the 'service' block
check {
type = "tcp" # TCP check on the 'db' port
port = "db" # Use the 'db' port label for health check
interval = "30s" # Interval between checks
timeout = "5s" # Timeout for each check
}
}
}
}
}