github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/website/content/docs/job-specification/service.mdx (about)

     1  ---
     2  layout: docs
     3  page_title: service Stanza - Job Specification
     4  sidebar_title: service
     5  description: |-
     6    The "service" stanza instructs Nomad to register the task as a service using
     7    the service discovery integration.
     8  ---
     9  
    10  # `service` Stanza
    11  
    12  <Placement
    13    groups={[
    14      ['job', 'group', 'service'],
    15      ['job', 'group', 'task', 'service'],
    16    ]}
    17  />
    18  
    19  The `service` stanza instructs Nomad to register a service with Consul. This
    20  section of the documentation will discuss the configuration, but please also
    21  read the [Nomad service discovery documentation][service-discovery] for more
    22  detailed information about the integration.
    23  
    24  ```hcl
    25  job "docs" {
    26    group "example" {
    27      task "server" {
    28        service {
    29          tags = ["leader", "mysql"]
    30  
    31          port = "db"
    32  
    33          meta {
    34            meta = "for your service"
    35          }
    36  
    37          check {
    38            type     = "tcp"
    39            port     = "db"
    40            interval = "10s"
    41            timeout  = "2s"
    42          }
    43  
    44          check {
    45            type     = "script"
    46            name     = "check_table"
    47            command  = "/usr/local/bin/check_mysql_table_status"
    48            args     = ["--verbose"]
    49            interval = "60s"
    50            timeout  = "5s"
    51  
    52            check_restart {
    53              limit = 3
    54              grace = "90s"
    55              ignore_warnings = false
    56            }
    57          }
    58        }
    59      }
    60    }
    61  }
    62  ```
    63  
    64  This section of the documentation only cover the job file fields and stanzas
    65  for service discovery. For more details on using Nomad with Consul please see
    66  the [Consul integration documentation][service-discovery].
    67  
    68  Nomad 0.10 also allows specifying the `service` stanza at the task group level.
    69  This enables services in the same task group to opt into [Consul
    70  Connect][connect] integration.
    71  
    72  ## `service` Parameters
    73  
    74  - `check` <code>([Check](#check-parameters): nil)</code> - Specifies a health
    75    check associated with the service. This can be specified multiple times to
    76    define multiple checks for the service. At this time, Nomad supports the
    77    `grpc`, `http`, `script`<sup><small>1</small></sup>, and `tcp` checks.
    78  
    79  - `connect` - Configures the [Consul Connect][connect] integration. Only
    80    available on group services.
    81  
    82  - `name` `(string: "<job>-<group>-<task>")` - Specifies the name this service
    83    will be advertised as in Consul. If not supplied, this will default to the
    84    name of the job, group, and task concatenated together with a dash, like
    85    `"docs-example-server"`. Each service must have a unique name within the
    86    cluster. Names must adhere to [RFC-1123
    87    §2.1](https://tools.ietf.org/html/rfc1123#section-2) and are limited to
    88    alphanumeric and hyphen characters (i.e. `[a-z0-9\-]`), and be less than 64
    89    characters in length.
    90  
    91    In addition to the standard [Nomad interpolation][interpolation], the
    92    following keys are also available:
    93  
    94    - `${JOB}` - the name of the job
    95    - `${GROUP}` - the name of the group
    96    - `${TASK}` - the name of the task
    97    - `${BASE}` - shorthand for `${JOB}-${GROUP}-${TASK}`
    98  
    99    Validation of the name occurs in two parts. When the job is registered, an initial validation pass checks that
   100    the service name adheres to RFC-1123 §2.1 and the length limit, excluding any variables requiring interpolation.
   101    Once the client receives the service and all interpretable values are available, the service name will be
   102    interpolated and revalidated. This can cause certain service names to pass validation at submit time but fail
   103    at runtime.
   104  
   105  - `port` `(string: <optional>)` - Specifies the port to advertise for this
   106    service. The value of `port` depends on which [`address_mode`](#address_mode)
   107    is being used:
   108  
   109    - `alloc` - Advertise the mapped `to` value of the labeled port and the allocation address.
   110      If a `to` value is not set, the port falls back to using the allocated host port. The `port`
   111      field may be a numeric port or a port label specified in the same group's network stanza.
   112  
   113    - `driver` - Advertise the port determined by the driver (e.g. Docker or rkt).
   114      The `port` may be a numeric port or a port label specified in the driver's
   115      `ports` field.
   116  
   117    - `host` - Advertise the host port for this service. `port` must match a port
   118      _label_ specified in the [`network`][network] stanza.
   119  
   120  - `tags` `(array<string>: [])` - Specifies the list of tags to associate with
   121    this service. If this is not supplied, no tags will be assigned to the service
   122    when it is registered.
   123  
   124  - `canary_tags` `(array<string>: [])` - Specifies the list of tags to associate with
   125    this service when the service is part of an allocation that is currently a
   126    canary. Once the canary is promoted, the registered tags will be updated to
   127    those specified in the `tags` parameter. If this is not supplied, the
   128    registered tags will be equal to that of the `tags` parameter.
   129  
   130  - `enable_tag_override` `(bool: false)` - Enables users of Consul's Catalog API
   131    to make changes to the tags of a service without having those changes be
   132    overwritten by Consul's anti-entropy mechanism. See Consul
   133    [documentation](https://www.consul.io/docs/internals/anti-entropy#enable-tag-override)
   134    for more information.
   135  
   136  - `address_mode` `(string: "auto")` - Specifies which address (host, alloc or
   137    driver-specific) this service should advertise. This setting is supported in
   138    Docker since Nomad 0.6 and rkt since Nomad 0.7. See [below for
   139    examples.](#using-driver-address-mode) Valid options are:
   140  
   141    - `alloc` - For allocations which create a network namespace, this address mode
   142      uses the IP address inside the namespace. Can only be used with "bridge" and "cni"
   143      [networking modes][network_mode]. A numeric port may be specified for situations
   144      where no port mapping is necessary. This mode can only be set for services which
   145      are defined in a "group" block.
   146  
   147    - `auto` - Allows the driver to determine whether the host or driver address
   148      should be used. Defaults to `host` and only implemented by Docker. If you
   149      use a Docker network plugin such as weave, Docker will automatically use
   150      its address.
   151  
   152    - `driver` - Use the IP specified by the driver, and the port specified in a
   153      port map. A numeric port may be specified since port maps aren't required
   154      by all network plugins. Useful for advertising SDN and overlay network
   155      addresses. Task will fail if driver network cannot be determined. Only
   156      implemented for Docker and rkt. This mode can only be set for services
   157      which are defined in a "task" block.
   158  
   159    - `host` - Use the host IP and port.
   160  
   161  - `task` `(string: "")` - Specifies the name of the Nomad task associated with
   162    this service definition. Only available on group services. Must be set if this
   163    service definition represents a Consul Connect-native service and there is more
   164    than one task in the task group.
   165  
   166  - `meta` <code>([Meta][]: nil)</code> - Specifies a key-value map that annotates
   167    the Consul service with user-defined metadata.
   168  
   169  - `canary_meta` <code>([Meta][]: nil)</code> - Specifies a key-value map that
   170    annotates the Consul service with user-defined metadata when the service is
   171    part of an allocation that is currently a canary. Once the canary is
   172    promoted, the registered meta will be updated to those specified in the
   173    `meta` parameter. If this is not supplied, the registered meta will be set to
   174    that of the `meta` parameter.
   175  
   176  - `on_update` `(string: "require_healthy")` - Specifies how checks should be
   177    evaluated when determining deployment health (including a job's initial
   178    deployment). This allows job submitters to define certain checks as readiness
   179    checks, progressing a deployment even if the Service's checks are not yet
   180    healthy. Checks inherit the Service's value by default. The check status is
   181    not altered in Consul and is only used to determine the check's health during
   182    an update.
   183  
   184    - `require_healthy` - In order for Nomad to consider the check healthy during
   185      an update it must report as healthy.
   186  
   187    - `ignore_warnings` - If a Service Check reports as warning, Nomad will treat
   188      the check as healthy. The Check will still be in a warning state in Consul.
   189  
   190    - `ignore` - Any status will be treated as healthy.
   191  
   192    ~> **Caveat:** `on_update` is only compatible with certain
   193    [`check_restart`][check_restart_stanza] configurations. `on_update =
   194    "ignore_warnings"` requires that `check_restart.ignore_warnings = true`.
   195    `check_restart` can however specify `ignore_warnings = true` with `on_update
   196    = "require_healthy"`. If `on_update` is set to `ignore`, `check_restart` must
   197    be omitted entirely.
   198  
   199  
   200  ### `check` Parameters
   201  
   202  Note that health checks run inside the task. If your task is a Docker container,
   203  the script will run inside the Docker container. If your task is running in a
   204  chroot, it will run in the chroot. Please keep this in mind when authoring check
   205  scripts.
   206  
   207  - `address_mode` `(string: "host")` - Same as `address_mode` on `service`.
   208    Unlike services, checks do not have an `auto` address mode as there's no way
   209    for Nomad to know which is the best address to use for checks. Consul needs
   210    access to the address for any HTTP or TCP checks. Added in Nomad 0.7.1. See
   211    [below for details.](#using-driver-address-mode) Unlike `port`, this setting
   212    is _not_ inherited from the `service`.
   213  
   214  - `args` `(array<string>: [])` - Specifies additional arguments to the
   215    `command`. This only applies to script-based health checks.
   216  
   217  - `check_restart` - See [`check_restart` stanza][check_restart_stanza].
   218  
   219  - `command` `(string: <varies>)` - Specifies the command to run for performing
   220    the health check. The script must exit: 0 for passing, 1 for warning, or any
   221    other value for a failing health check. This is required for script-based
   222    health checks.
   223  
   224    ~> **Caveat:** The command must be the path to the command on disk, and no
   225    shell exists by default. That means operators like `||` or `&&` are not
   226    available. Additionally, all arguments must be supplied via the `args`
   227    parameter. To achieve the behavior of shell operators, specify the command
   228    as a shell, like `/bin/bash` and then use `args` to run the check.
   229  
   230  - `grpc_service` `(string: <optional>)` - What service, if any, to specify in
   231    the gRPC health check. gRPC health checks require Consul 1.0.5 or later.
   232  
   233  - `grpc_use_tls` `(bool: false)` - Use TLS to perform a gRPC health check. May
   234    be used with `tls_skip_verify` to use TLS but skip certificate verification.
   235  
   236  - `initial_status` `(string: <enum>)` - Specifies the originating status of the
   237    service. Valid options are the empty string, `passing`, `warning`, and
   238    `critical`.
   239  
   240  - `success_before_passing` `(int:0)` - The number of consecutive successful checks
   241    required before Consul will transition the service status to [`passing`][consul_passfail].
   242  
   243  - `failures_before_critical` `(int:0)` - The number of consecutive failing checks
   244    required before Consul will transition the service status to [`critical`][consul_passfail].
   245  
   246  - `interval` `(string: <required>)` - Specifies the frequency of the health checks
   247    that Consul will perform. This is specified using a label suffix like "30s"
   248    or "1h". This must be greater than or equal to "1s".
   249  
   250  - `method` `(string: "GET")` - Specifies the HTTP method to use for HTTP
   251    checks.
   252  
   253  - `name` `(string: "service: <name> check")` - Specifies the name of the health
   254    check. If the name is not specified Nomad generates one based on the service name.
   255    If you have more than one check you must specify the name.
   256  
   257  - `path` `(string: <varies>)` - Specifies the path of the HTTP endpoint which
   258    Consul will query to query the health of a service. Nomad will automatically
   259    add the IP of the service and the port, so this is just the relative URL to
   260    the health check endpoint. This is required for http-based health checks.
   261  
   262  - `expose` `(bool: false)` - Specifies whether an [Expose Path](/docs/job-specification/expose#path-parameters)
   263    should be automatically generated for this check. Only compatible with
   264    Connect-enabled task-group services using the default Connect proxy. If set, check
   265    [`type`][type] must be `http` or `grpc`, and check `name` must be set.
   266  
   267  - `port` `(string: <varies>)` - Specifies the label of the port on which the
   268    check will be performed. Note this is the _label_ of the port and not the port
   269    number unless `address_mode = driver`. The port label must match one defined
   270    in the [`network`][network] stanza. If a port value was declared on the
   271    `service`, this will inherit from that value if not supplied. If supplied,
   272    this value takes precedence over the `service.port` value. This is useful for
   273    services which operate on multiple ports. `grpc`, `http`, and `tcp` checks
   274    require a port while `script` checks do not. Checks will use the host IP and
   275    ports by default. In Nomad 0.7.1 or later numeric ports may be used if
   276    `address_mode="driver"` is set on the check.
   277  
   278  - `protocol` `(string: "http")` - Specifies the protocol for the http-based
   279    health checks. Valid options are `http` and `https`.
   280  
   281  - `task` `(string: <required>)` - Specifies the task associated with this
   282    check. Scripts are executed within the task's environment, and
   283    `check_restart` stanzas will apply to the specified task. For `checks` on group
   284    level `services` only. Inherits the [`service.task`][service_task] value if not
   285    set.
   286  
   287  - `timeout` `(string: <required>)` - Specifies how long Consul will wait for a
   288    health check query to succeed. This is specified using a label suffix like
   289    "30s" or "1h". This must be greater than or equal to "1s"
   290  
   291    ~> **Caveat:** Script checks use the task driver to execute in the task's
   292    environment. For task drivers with namespace isolation such as `docker` or
   293    `exec`, setting up the context for the script check may take an unexpectedly
   294    long amount of time (a full second or two), especially on busy hosts. The
   295    timeout configuration must allow for both this setup and the execution of
   296    the script. Operators should use long timeouts (5 or more seconds) for script
   297    checks, and monitor telemetry for
   298    `client.allocrunner.taskrunner.tasklet_timeout`.
   299  
   300  - `type` `(string: <required>)` - This indicates the check types supported by
   301    Nomad. Valid options are `grpc`, `http`, `script`, and `tcp`. gRPC health
   302    checks require Consul 1.0.5 or later.
   303  
   304  - `tls_skip_verify` `(bool: false)` - Skip verifying TLS certificates for HTTPS
   305    checks. Requires Consul >= 0.7.2.
   306  
   307  - `on_update` `(string: "require_healthy")` - Specifies how checks should be
   308    evaluated when determining deployment health (including a job's initial
   309    deployment). This allows job submitters to define certain checks as readiness
   310    checks, progressing a deployment even if the Service's checks are not yet
   311    healthy. Checks inherit the Service's value by default. The check status is
   312    not altered in Consul and is only used to determine the check's health during
   313    an update.
   314  
   315    - `require_healthy` - In order for Nomad to consider the check healthy during
   316      an update it must report as healthy.
   317  
   318    - `ignore_warnings` - If a Service Check reports as warning, Nomad will treat
   319      the check as healthy. The Check will still be in a warning state in Consul.
   320  
   321    - `ignore` - Any status will be treated as healthy.
   322  
   323    ~> **Caveat:** `on_update` is only compatible with certain
   324    [`check_restart`][check_restart_stanza] configurations. `on_update =
   325    "ignore_warnings"` requires that `check_restart.ignore_warnings = true`.
   326    `check_restart` can however specify `ignore_warnings = true` with `on_update
   327    = "require_healthy"`. If `on_update` is set to `ignore`, `check_restart` must
   328    be omitted entirely.
   329  
   330  #### `header` Stanza
   331  
   332  HTTP checks may include a `header` stanza to set HTTP headers. The `header`
   333  stanza parameters have lists of strings as values. Multiple values will cause
   334  the header to be set multiple times, once for each value.
   335  
   336  ```hcl
   337  service {
   338    # ...
   339    check {
   340      type     = "http"
   341      port     = "lb"
   342      path     = "/_healthz"
   343      interval = "5s"
   344      timeout  = "2s"
   345      header {
   346        Authorization = ["Basic ZWxhc3RpYzpjaGFuZ2VtZQ=="]
   347      }
   348    }
   349  }
   350  ```
   351  
   352  ## `service` Lifecycle
   353  
   354  Nomad manages registering, updating, and deregistering services with Consul. It
   355  is important to understand when each of these steps happens and how they can be
   356  customized.
   357  
   358  **Registration**: Nomad will register `group` services and checks _before_
   359  starting any tasks. Services and checks for a specific `task` are registered
   360  _after_ the task has started.
   361  
   362  **Updating**: If a service or check definition is updated, Nomad will update
   363  the service in Consul as well. Consul is updated without restarting a task.
   364  
   365  **Deregistering**: If a running task with a service stanza exits, the services
   366  and checks are immediately deregistered from Consul without delay. If however
   367  Nomad needs to kill a running task, the task is killed in the following order:
   368  
   369  1. Immediately remove the services and checks from Consul. This stops new
   370     traffic from being routed to the task that is being killed.
   371  2. If [`shutdown_delay`][shutdowndelay] is set, wait the configured duration
   372     before proceeding to step 3. Setting a [`shutdown_delay`][shutdowndelay] can
   373     be useful if the application itself doesn't handle graceful shutdowns based
   374     on the [`kill_signal`][killsignal]. The configured delay will provide a
   375     period of time in which the service is no longer registered in Consul, and
   376     thus is not receiving additional requests, but hasn't been signalled to
   377     shutdown. This allows the application time to complete the requests and
   378     become idle.
   379  3. Send the [`kill_signal`][killsignal] to the task and wait for the task to
   380     exit. The task should use this time to gracefully drain and finish any
   381     existing requests.
   382  4. If the task has not exited after the [`kill_timeout`][killtimeout], Nomad
   383     will force kill the application.
   384  
   385  ## `service` Examples
   386  
   387  The following examples only show the `service` stanzas. Remember that the
   388  `service` stanza is only valid in the placements listed above.
   389  
   390  ### Basic Service
   391  
   392  This example registers a service named "load-balancer" with no health checks.
   393  
   394  ```hcl
   395  service {
   396    name = "load-balancer"
   397    port = "lb"
   398  }
   399  ```
   400  
   401  This example must be accompanied by a [`network`][network] stanza which defines
   402  a static or dynamic port labeled "lb". For example:
   403  
   404  ```hcl
   405  network {
   406    port "lb" {}
   407  }
   408  ```
   409  
   410  ### Script Checks with Shells
   411  
   412  This example shows a service with a script check that is evaluated and interpolated in a shell; it
   413  tests whether a file is present at `${HEALTH_CHECK_FILE}` environment variable:
   414  
   415  ```hcl
   416  service {
   417    check {
   418      type    = "script"
   419      command = "/bin/bash"
   420      args    = ["-c", "test -f ${HEALTH_CHECK_FILE}"]
   421    }
   422  }
   423  ```
   424  
   425  Using `/bin/bash` (or another shell) is required here to interpolate the `${HEALTH_CHECK_FILE}` value.
   426  
   427  The following examples of `command` fields **will not work**:
   428  
   429  ```hcl
   430  # invalid because command is not a path
   431  check {
   432    type    = "script"
   433    command = "test -f /tmp/file.txt"
   434  }
   435  
   436  # invalid because path will not be interpolated
   437  check {
   438    type    = "script"
   439    command = "/bin/test"
   440    args    = ["-f", "${HEALTH_CHECK_FILE}"]
   441  }
   442  ```
   443  
   444  ### HTTP Health Check
   445  
   446  This example shows a service with an HTTP health check. This will query the
   447  service on the IP and port registered with Nomad at `/_healthz` every 5 seconds,
   448  giving the service a maximum of 2 seconds to return a response, and include an
   449  Authorization header. Any non-2xx code is considered a failure.
   450  
   451  ```hcl
   452  service {
   453    check {
   454      type     = "http"
   455      port     = "lb"
   456      path     = "/_healthz"
   457      interval = "5s"
   458      timeout  = "2s"
   459      header {
   460        Authorization = ["Basic ZWxhc3RpYzpjaGFuZ2VtZQ=="]
   461      }
   462    }
   463  }
   464  ```
   465  
   466  ### Multiple Health Checks
   467  
   468  This example shows a service with multiple health checks defined. All health
   469  checks must be passing in order for the service to register as healthy.
   470  
   471  ```hcl
   472  service {
   473    check {
   474      name     = "HTTP Check"
   475      type     = "http"
   476      port     = "lb"
   477      path     = "/_healthz"
   478      interval = "5s"
   479      timeout  = "2s"
   480    }
   481  
   482    check {
   483      name     = "HTTPS Check"
   484      type     = "http"
   485      protocol = "https"
   486      port     = "lb"
   487      path     = "/_healthz"
   488      interval = "5s"
   489      timeout  = "2s"
   490      method   = "POST"
   491    }
   492  
   493    check {
   494      name      = "Postgres Check"
   495      type      = "script"
   496      command   = "/usr/local/bin/pg-tools"
   497      args      = ["verify", "database", "prod", "up"]
   498      interval  = "5s"
   499      timeout   = "2s"
   500      on_update = "ignore_warnings"
   501    }
   502  }
   503  ```
   504  
   505  ### Readiness and Liveness Checks
   506  
   507  Multiple checks for a service can be composed to create liveness and readiness
   508  checks by configuring [`on_update`][on_update] for the check.
   509  
   510  ```hcl
   511  service {
   512    # This is a liveness check that will be used to verify the service
   513    # is up and able to serve traffic
   514    check {
   515      name     = "tcp_validate"
   516      type     = "tcp"
   517      port     = 6379
   518      interval = "10s"
   519      timeout  = "2s"
   520    }
   521  
   522    # This is a readiness check that is used to verify that, for example, the
   523    # application has elected a leader between allocations. Warnings from
   524    # this check will be ignored during updates.
   525    check {
   526      name      = "leader-check"
   527      type      = "script"
   528      command   = "/bin/bash"
   529      interval  = "30s"
   530      timeout   = "10s"
   531      task      = "server"
   532      on_update = "ignore_warnings"
   533  
   534      args = [
   535        "-c",
   536        "echo 'service is not the leader'; exit 1;",
   537      ]
   538    }
   539  }
   540  ```
   541  
   542  ### gRPC Health Check
   543  
   544  gRPC health checks use the same host and port behavior as `http` and `tcp`
   545  checks, but gRPC checks also have an optional gRPC service to health check. Not
   546  all gRPC applications require a service to health check. gRPC health checks
   547  require Consul 1.0.5 or later.
   548  
   549  ```hcl
   550  service {
   551    check {
   552      type            = "grpc"
   553      port            = "rpc"
   554      interval        = "5s"
   555      timeout         = "2s"
   556      grpc_service    = "example.Service"
   557      grpc_use_tls    = true
   558      tls_skip_verify = true
   559    }
   560  }
   561  ```
   562  
   563  In this example Consul would health check the `example.Service` service on the
   564  `rpc` port defined in the task's [network resources][network] stanza. See
   565  [Using Driver Address Mode](#using-driver-address-mode) for details on address
   566  selection.
   567  
   568  ### Using Driver Address Mode
   569  
   570  The [Docker](/docs/drivers/docker#network_mode) and
   571  [rkt](/docs/drivers/rkt#net) drivers support the `driver` setting for the
   572  `address_mode` parameter in both `service` and `check` stanzas. The driver
   573  address mode allows advertising and health checking the IP and port assigned to
   574  a task by the driver. This way, if you're using a network plugin like Weave with
   575  Docker, you can advertise the Weave address in Consul instead of the host's
   576  address.
   577  
   578  For example if you were running the example Redis job in an environment with
   579  Weave but Consul was running on the host you could use the following
   580  configuration:
   581  
   582  ```hcl
   583  job "example" {
   584    datacenters = ["dc1"]
   585  
   586    network {
   587      port "db" {
   588        to = 6379
   589      }
   590    }
   591  
   592    group "cache" {
   593  
   594      task "redis" {
   595        driver = "docker"
   596  
   597        config {
   598          image = "redis:3.2"
   599          network_mode = "weave"
   600          ports = ["db"]
   601        }
   602  
   603        resources {
   604          cpu    = 500 # 500 MHz
   605          memory = 256 # 256MB
   606        }
   607  
   608        service {
   609          name = "weave-redis"
   610          port = "db"
   611          check {
   612            name     = "host-redis-check"
   613            type     = "tcp"
   614            interval = "10s"
   615            timeout  = "2s"
   616          }
   617        }
   618      }
   619    }
   620  }
   621  ```
   622  
   623  No explicit `address_mode` required.
   624  
   625  Services default to the `auto` address mode. When a Docker network mode other
   626  than "host" or "bridge" is used, services will automatically advertise the
   627  driver's address (in this case Weave's). The service will advertise the
   628  container's port: 6379.
   629  
   630  However since Consul is often run on the host without access to the Weave
   631  network, `check` stanzas default to `host` address mode. The TCP check will run
   632  against the host's IP and the dynamic host port assigned by Nomad.
   633  
   634  Note that the `check` still inherits the `service` stanza's `db` port label,
   635  but each will resolve the port label according to their address mode.
   636  
   637  If Consul has access to the Weave network the job could be configured like
   638  this:
   639  
   640  ```hcl
   641  job "example" {
   642    datacenters = ["dc1"]
   643    group "cache" {
   644  
   645      task "redis" {
   646        driver = "docker"
   647  
   648        config {
   649          image = "redis:3.2"
   650          network_mode = "weave"
   651          # No port map required.
   652        }
   653  
   654        resources {
   655          cpu    = 500 # 500 MHz
   656          memory = 256 # 256MB
   657        }
   658  
   659        service {
   660          name = "weave-redis"
   661          port = 6379
   662          address_mode = "driver"
   663          check {
   664            name     = "host-redis-check"
   665            type     = "tcp"
   666            interval = "10s"
   667            timeout  = "2s"
   668            port     = 6379
   669  
   670            address_mode = "driver"
   671          }
   672        }
   673      }
   674    }
   675  }
   676  ```
   677  
   678  In this case Nomad doesn't need to assign Redis any host ports. The `service`
   679  and `check` stanzas can both specify the port number to advertise and check
   680  directly since Nomad isn't managing any port assignments.
   681  
   682  ### IPv6 Docker containers
   683  
   684  The [Docker](/docs/drivers/docker#advertise_ipv6_address) driver supports the
   685  `advertise_ipv6_address` parameter in its configuration.
   686  
   687  Services will automatically advertise the IPv6 address when `advertise_ipv6_address`
   688  is used.
   689  
   690  Unlike services, checks do not have an `auto` address mode as there's no way
   691  for Nomad to know which is the best address to use for checks. Consul needs
   692  access to the address for any HTTP or TCP checks.
   693  
   694  So you have to set `address_mode` parameter in the `check` stanza to `driver`.
   695  
   696  For example using `auto` address mode:
   697  
   698  ```hcl
   699  job "example" {
   700    datacenters = ["dc1"]
   701    group "cache" {
   702  
   703      network {
   704        port "db" {
   705          to = 6379
   706        }
   707      }
   708  
   709  
   710      task "redis" {
   711        driver = "docker"
   712  
   713        config {
   714          image = "redis:3.2"
   715          advertise_ipv6_address = true
   716          ports = ["db"]
   717        }
   718  
   719        resources {
   720          cpu    = 500 # 500 MHz
   721          memory = 256 # 256MB
   722        }
   723  
   724        service {
   725          name = "ipv6-redis"
   726          port = "db"
   727          check {
   728            name     = "ipv6-redis-check"
   729            type     = "tcp"
   730            interval = "10s"
   731            timeout  = "2s"
   732            port     = "db"
   733            address_mode = "driver"
   734          }
   735        }
   736      }
   737    }
   738  }
   739  ```
   740  
   741  Or using `address_mode=driver` for `service` and `check` with numeric ports:
   742  
   743  ```hcl
   744  job "example" {
   745    datacenters = ["dc1"]
   746    group "cache" {
   747  
   748      task "redis" {
   749        driver = "docker"
   750  
   751        config {
   752          image = "redis:3.2"
   753          advertise_ipv6_address = true
   754          # No port map required.
   755        }
   756  
   757        resources {
   758          cpu    = 500 # 500 MHz
   759          memory = 256 # 256MB
   760        }
   761  
   762        service {
   763          name = "ipv6-redis"
   764          port = 6379
   765          address_mode = "driver"
   766          check {
   767            name     = "ipv6-redis-check"
   768            type     = "tcp"
   769            interval = "10s"
   770            timeout  = "2s"
   771            port     = 6379
   772            address_mode = "driver"
   773          }
   774        }
   775      }
   776    }
   777  }
   778  ```
   779  
   780  The `service` and `check` stanzas can both specify the port number to
   781  advertise and check directly since Nomad isn't managing any port assignments.
   782  
   783  ---
   784  
   785  <sup>
   786    <small>1</small>
   787  </sup>
   788  <small>
   789    {' '}
   790    Script checks are not supported for the QEMU driver since the Nomad
   791    client does not have access to the file system of a task for that driver.
   792  </small>
   793  
   794  [check_restart_stanza]: /docs/job-specification/check_restart
   795  [consul_grpc]: https://www.consul.io/api/agent/check#grpc
   796  [consul_passfail]: https://www.consul.io/docs/agent/checks#success-failures-before-passing-critical
   797  [service-discovery]: /docs/integrations/consul-integration#service-discovery 'Nomad Service Discovery'
   798  [interpolation]: /docs/runtime/interpolation 'Nomad Runtime Interpolation'
   799  [network]: /docs/job-specification/network 'Nomad network Job Specification'
   800  [qemu]: /docs/drivers/qemu 'Nomad QEMU Driver'
   801  [restart_stanza]: /docs/job-specification/restart 'restart stanza'
   802  [connect]: /docs/job-specification/connect 'Nomad Consul Connect Integration'
   803  [type]: /docs/job-specification/service#type
   804  [shutdowndelay]: /docs/job-specification/task#shutdown_delay
   805  [killsignal]: /docs/job-specification/task#kill_signal
   806  [killtimeout]: /docs/job-specification/task#kill_timeout
   807  [service_task]: /docs/job-specification/service#task-1
   808  [network_mode]: /docs/job-specification/network#mode
   809  [on_update]: /docs/job-specification/service#on_update