Simple dynamic port mapping

You should not use the -p argument when mapping ports in Nomad. Instead, use the ports = [ ] argument in the Docker configuration. There’s more information in the Allocating Ports section of the Nomad Docker task driver documentation. You will also need to use the information in Using the Port Map from the same page since your job doesn’t seem to expect to find the port configuration in the environment.

I made an example container based on the Dockerizing a Node.js web app example , which uses 8080 as the application’s port. Here’s the configuration that I used to connect it to my Nomad-generated port.

job "webapp" {
	datacenters = ["dc1"]

	group "example" {
		network {
			mode = "host"
			port "http" {
				to = "8080"
			}
		}

		task "app" {
			driver = "docker"

			config {
				image = "voiselle/node-web-app"
				ports = ["http"]
			}
		}
	}
}

Hopefully this gets you unstuck.

Best,
Charlie