Accessing container IP from inside container

20 Views Asked by At

I have podman based nomad job specs that register services with consul using address_mode = driver, meaning the IP/port pair sent to consul is the container IP and port, something allocated from my container cidr of 172.25.0.0/16 — no problems here, that’s exactly what I want.

Can I get nomad to expose the same IP/port pair into the container? With the following configuration, NOMAD_IP_<label> points to 127.0.0.1 — that doesn’t work for my use case.

job "example" {
  type        = "service"

  group "webserver" {
    network {
      port "https" {
        to = 443
      }
    }

    task "caddy" {
      driver = "podman"

      config {
        image = "docker://docker.io/library/caddy"
        ports = ["https"]
      }

      service {
          provider     = "consul"
          port         = "https"
          address_mode = "driver"
      }
    }
  }
}
1

There are 1 best solutions below

0
KamilCuk On

There is still undocumented NOMAD_HOST_IP_ https://github.com/hashicorp/nomad/blob/14280e0820b616ebbb15f91257859a0338bb3d4e/client/taskenv/env.go#L104 .

If you want to use network interfaces from host, then do not virtualize network stack. See https://developer.hashicorp.com/nomad/plugins/drivers/podman#network_mode .