How would you use Hashicorp's Nomad 'template stanza' to generate an nginx config file through the Nomad job file?

With the assumption that Consul and Nomad has been configured to run on a pool of resource. How would you rendered a template file for the sole purpose of generating e.g. an Nginx ‘default.conf’ file.

Using the template stanza configuration below, as an example; Nomad fails to generate a default.conf ‘file’; instead a default.conf ‘directory’ is created.

  • consul-template using Address not ServiceAddress in template
  • Issues with running a consul docker health check
  • Unable to load balance using Docker, Consul and nginx
  • I could curl using IP but not using consul serviceName?
  • how does consul work with redshift?
  • Consul cluster automatic bootstrap on docker
  • template {
        source        = "/path/to/tmp.ctmpl"
        destination   = "folder/default.conf"
        change_mode   = "restart"
        change_signal = "SIGINT"

    I’m either missing a trick, or have misunderstood the functionalities of the ‘template stanza’.

    One of the issue with the template generating a directory rather than a file is, you cannot mount a directory to a config file path. So running a task that uses the Nomad docker driver with the exemplar ‘docker’ volume config results in an error.

    volumes = ["/path/to/job/folder/default.conf:/etc/nginx/conf.d/default.conf" ]

    Or is it impossible to have the template stanza generate a config file?

    *P.s. Using Nomad build 0.5.5**

  • Unable to pull docker image with concourse - Verifying Checksum error
  • How do I get the container ID of a non-running container?
  • difference between cmd and entrypoint in dockefile
  • Docker - Execute command after mounting a volume
  • docker-compose how to run container with bind 1-to-1 ports on ip aliasing interface
  • When to Use Docker's Container Name?
  • One Solution collect form web for “How would you use Hashicorp's Nomad 'template stanza' to generate an nginx config file through the Nomad job file?”

    I just put together a little Nomad job showing this working, so you may have a slight configuration error. To allow you to run the job yourself I have made it available as a gist here. In the same gist I have a nginx.conf that has nginx listen on whatever port is in the Nomad job file.

    Here is the Nomad job:

    job "nginx" {
      datacenters = ["dc1"]
      type = "service"
      group "cache" {
        count = 1
        task "redis" {
          driver = "docker"
          config {
            image = "nginx:1.11.10"
            volumes = ["new/default.conf:/etc/nginx/conf.d/default.conf" ]
            network_mode = "host"
          artifact {
            source = ""
          template {
            source        = "local/nginx.conf"
            destination   = "new/default.conf"
            change_mode   = "restart"
          resources {
            network {
              mbits = 10
              port "nginx" {
                static = 8080

    I can then query that address and see that nginx is bound to that port, thus the template being mounted is working properly.

    $ curl
    <!DOCTYPE html>
    <title>Welcome to nginx!</title>
        body {
            width: 35em;
            margin: 0 auto;
            font-family: Tahoma, Verdana, Arial, sans-serif;
    <h1>Welcome to nginx!</h1>
    <p>If you see this page, the nginx web server is successfully installed and
    working. Further configuration is required.</p>
    <p>For online documentation and support please refer to
    <a href=""></a>.<br/>
    Commercial support is available at
    <a href=""></a>.</p>
    <p><em>Thank you for using nginx.</em></p>

    If you take a look at the gist, I show the file being rendered and mounted properly as well.

    Hope this helps you! Also be sure to check out the community page for getting help. We have both a Gitter room and a mailing list.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.