1

with following job config. curl NOMAD_IP_http:NOMAD_PORT_http cannot access http-echo service.

there is no listenig port on localhost for incomming request.

why and how to access the http-echo service


job "job" {
  datacenters = ["dc1"]
  group "group" {
    count = 2
    network {        
      port "http" {}
    }
    service {
      name = "http-echo"
      port = "http"
      tags = [
        "http-echo",
      ]
      check {
        type      = "http"
        path      = "/health"
        interval  = "30s"
        timeout   = "2s"
      }
    }
    task "task" {
      driver = "docker"
      config {
        image = "hashicorp/http-echo:latest"
        args = [
          "-listen", ":${NOMAD_PORT_http}",
          "-text", "Hello and welcome to ${NOMAD_IP_http} running on port ${NOMAD_PORT_http}",
        ]
      }
      resources {}
    }
  }
}

UPDATE

after config driver network_mode, curl successfully.

network_mode = "host"

eins
  • 43
  • 1
  • 6

1 Answers1

0

You forgot to add ports at job -> group -> task ->ports

Now it works on latest nomad(v1.1.3+).

job "job" {
  datacenters = ["dc1"]
  group "group" {
    count = 2
    network {        
      port "http" {}
      # or maps to container's default port
      # port "http" {
      #    to = 5678
      # }
      # 
    }
    service {
      name = "http-echo"
      port = "http"
      tags = [
        "http-echo",
      ]
      check {
        type      = "http"
        path      = "/health"
        interval  = "30s"
        timeout   = "2s"
      }
    }
    task "task" {
      driver = "docker"
      config {
        image = "hashicorp/http-echo:latest"
        args = [
          "-listen", ":${NOMAD_PORT_http}",
          "-text", "Hello and welcome to ${NOMAD_IP_http} running on port ${NOMAD_PORT_http}",
        ]
        ports = ["http"]
      }
      resources {}
    }
  }
}

Then run docker ps, you will get the mapped port, and curl works.

Miao1007
  • 944
  • 6
  • 22