Dockerize nomad

Can somebody please help me with dockerizing nomad. Do we have to write separate docker-compose files for client and server.
I am currently having a single client and single server. Here is my client.hcl -

log_level = "DEBUG"

data_dir = "/tmp/client"

name = "client"
client {

    gc_disk_usage_threshold = 100
    enabled = true
    options {
      "driver.raw-exec.enable" = "1"
    }
    servers = ["localhost:4647"]
}
ports {
    http = 5656
}
plugin "raw_exec" {
  config {
    enabled = true
  }
}

Herer is my server.hcl

log_level = "DEBUG"

data_dir = "/tmp/server"
bind_addr  = "localhost"

advertise {
  http = "localhost"
  rpc  = "localhost"
  serf = "localhost:4648" 
}

server {
    enabled = true
     
    bootstrap_expect = 1
}

Thanks in advance.

1 Like

Philosophically speaking this is not recommended; there have been various requests (GitHub issues).

Thought:
If something that controls “containers”, runs inside a container, it causes a dependency on the container runtime to be working all the time! :thinking:

If you want to use a single node, the same binary can be used as a server and client.

Disclaimer: This is my personal opinion. I do not work for HashiCorp! :smile:

Hi @shoryavj! If you take a look on GitHub you can find a couple of issues where folks have asked about running Nomad in Docker (ex https://github.com/hashicorp/nomad/issues/6487).

But seeing as how you’re using Docker Compose here, my guess is you’re just worried about having a local development environment? I mostly use Vagrant for that sort of thing, but I know a few people have hacked together something using Compose. In that case, there’s a few things to think about:

  • You can run the client and server in the same container in this case.
  • You’ll want to mount a volume for Nomad’s data_dir to persist state between container restarts.
  • Alternately, if you don’t need persistence, you might want to consider running Nomad in dev mode instead.
  • If you want to use Docker tasks, you’ll need to bind the docker socket into the Nomad container.
  • If you want to use raw_exec tasks, you’ll need to make sure that the binaries are accessible to the Nomad client’s container because that’s where they’ll run. (Either inside the container or maybe bind-mounted into it if they’re statically linked.)

I published a simple docker-compose.yml + Dockerfile for Nomad for working with local development workflows. Sharing here in case someone finds it useful.

1 Like

For development purposes, I sometimes run Nomad-in-Nomad using the raw_exec task driver:

Managing the static ports is a bit annoying, but it gets the job done :grinning_face_with_smiling_eyes:

1 Like