I am trying to use the nomad service discovery to connect services in a bridge network the template block output resolves .Address as 127.0.0.1 instead of the container IP.
I have the following configs when trying this out.
job "test" {
datacenters = ["dc1"]
type = "service"
group "test" {
count = 1
network {
mode = "bridge"
port "http" { }
}
task "nginx" {
driver = "docker"
config {
image = "nginx"
ports = ["http"]
}
service {
name = "test"
port = "http"
provider = "nomad"
}
env {
NGINX_PORT = "${NOMAD_PORT_http}"
}
}
}
}
job "busybox" {
datacenters = ["dc1"]
type = "service"
group "busybox" {
count = 1
network {
mode = "bridge"
}
task "sleep" {
driver = "docker"
template {
data = <<EOH
{{$allocID := env "NOMAD_ALLOC_ID" -}}
{{range nomadService 1 $allocID "test"}}
TEST="{{.Address}}:{{.Port}}"
{{ end}}
EOH
destination = "/tmp/env.local"
}
config {
image = "busybox"
command = "/bin/sh"
args = [
"-c",
"sleep 500"
]
}
}
}
}
When checking the resulting file it looks like this:
TEST="127.0.0.1:24258"