github.com/ferranbt/nomad@v0.9.3-0.20190607002617-85c449b7667c/website/source/docs/drivers/docker.html.md (about)

     1  ---
     2  layout: "docs"
     3  page_title: "Drivers: Docker"
     4  sidebar_current: "docs-drivers-docker"
     5  description: |-
     6    The Docker task driver is used to run Docker based tasks.
     7  ---
     8  
     9  # Docker Driver
    10  
    11  Name: `docker`
    12  
    13  The `docker` driver provides a first-class Docker workflow on Nomad. The Docker
    14  driver handles downloading containers, mapping ports, and starting, watching,
    15  and cleaning up after containers.
    16  
    17  ## Task Configuration
    18  
    19  ```hcl
    20  task "webservice" {
    21    driver = "docker"
    22  
    23    config {
    24      image = "redis:3.2"
    25      labels {
    26        group = "webservice-cache"
    27      }
    28    }
    29  }
    30  ```
    31  
    32  The `docker` driver supports the following configuration in the job spec.  Only
    33  `image` is required.
    34  
    35  * `image` - The Docker image to run. The image may include a tag or custom URL
    36    and should include `https://` if required. By default it will be fetched from
    37    Docker Hub. If the tag is omitted or equal to `latest` the driver will always
    38    try to pull the image. If the image to be pulled exists in a registry that
    39    requires authentication credentials must be provided to Nomad. Please see the
    40    [Authentication section](#authentication).
    41  
    42      ```hcl
    43      config {
    44        image = "https://hub.docker.internal/redis:3.2"
    45      }
    46      ```
    47  
    48  * `args` - (Optional) A list of arguments to the optional `command`. If no
    49    `command` is specified, the arguments are passed directly to the container.
    50    References to environment variables or any [interpretable Nomad
    51    variables](/docs/runtime/interpolation.html) will be interpreted before
    52    launching the task. For example:
    53  
    54      ```hcl
    55      config {
    56        args = [
    57          "-bind", "${NOMAD_PORT_http}",
    58          "${nomad.datacenter}",
    59          "${MY_ENV}",
    60          "${meta.foo}",
    61        ]
    62      }
    63      ```
    64  
    65  * `auth` - (Optional) Provide authentication for a private registry (see below).
    66  
    67  * `auth_soft_fail` `(bool: false)` - Don't fail the task on an auth failure.
    68    Attempt to continue without auth.
    69  
    70  * `command` - (Optional) The command to run when starting the container.
    71  
    72      ```hcl
    73      config {
    74        command = "my-command"
    75      }
    76      ```
    77  
    78  * `dns_search_domains` - (Optional) A list of DNS search domains for the container
    79    to use.
    80  
    81  * `dns_options` - (Optional) A list of DNS options for the container to use.
    82  
    83  * `dns_servers` - (Optional) A list of DNS servers for the container to use
    84    (e.g. ["8.8.8.8", "8.8.4.4"]). Requires Docker v1.10 or greater.
    85  
    86  * `entrypoint` - (Optional) A string list overriding the image's entrypoint.
    87  
    88  * `extra_hosts` - (Optional) A list of hosts, given as host:IP, to be added to
    89    `/etc/hosts`.
    90  
    91  * `force_pull` - (Optional) `true` or `false` (default). Always pull most recent image
    92    instead of using existing local image. Should be set to `true` if repository tags
    93    are mutable.  If image's tag is `latest` or omitted, the image will always be pulled
    94    regardless of this setting.
    95  
    96  * `hostname` - (Optional) The hostname to assign to the container. When
    97    launching more than one of a task (using `count`) with this option set, every
    98    container the task starts will have the same hostname.
    99  
   100  * `interactive` - (Optional) `true` or `false` (default). Keep STDIN open on
   101    the container.
   102  
   103  * `sysctl` - (Optional) A key-value map of sysctl configurations to set to the
   104     containers on start.
   105  
   106      ```hcl
   107      config {
   108        sysctl {
   109          net.core.somaxconn = "16384"
   110        }
   111      }
   112      ```
   113  
   114  * `ulimit` - (Optional) A key-value map of ulimit configurations to set to the
   115    containers on start.
   116  
   117      ```hcl
   118      config {
   119        ulimit {
   120          nproc = "4242"
   121          nofile = "2048:4096"
   122        }
   123      }
   124      ```
   125  
   126  * `privileged` - (Optional) `true` or `false` (default). Privileged mode gives
   127    the container access to devices on the host. Note that this also requires the
   128    nomad agent and docker daemon to be configured to allow privileged
   129    containers.
   130  
   131  * `ipc_mode` - (Optional) The IPC mode to be used for the container. The default
   132    is `none` for a private IPC namespace. Other values are `host` for sharing
   133    the host IPC namespace or the name or id of an existing container. Note that
   134    it is not possible to refer to Docker containers started by Nomad since their
   135    names are not known in advance. Note that setting this option also requires the
   136    Nomad agent to be configured to allow privileged containers.
   137  
   138  * `ipv4_address` - (Optional) The IPv4 address to be used for the container when
   139    using user defined networks. Requires Docker 1.13 or greater.
   140  
   141  * `ipv6_address` - (Optional) The IPv6 address to be used for the container when
   142    using user defined networks. Requires Docker 1.13 or greater.
   143  
   144  * `labels` - (Optional) A key-value map of labels to set to the containers on
   145    start.
   146  
   147      ```hcl
   148      config {
   149        labels {
   150          foo = "bar"
   151          zip = "zap"
   152        }
   153      }
   154      ```
   155  
   156  * `load` - (Optional) Load an image from a `tar` archive file instead of from a
   157    remote repository. Equivalent to the `docker load -i <filename>` command.
   158  
   159      ```hcl
   160      artifact {
   161        source = "http://path.to/redis.tar"
   162      }
   163      config {
   164        load = "redis.tar"
   165        image = "redis"
   166      }
   167      ```
   168  
   169  * `logging` - (Optional) A key-value map of Docker logging options. The default
   170    value is `syslog`.
   171  
   172      ```hcl
   173      config {
   174        logging {
   175          type = "fluentd"
   176          config {
   177            fluentd-address = "localhost:24224"
   178            tag = "your_tag"
   179          }
   180        }
   181      }
   182      ```
   183  
   184  * `mac_address` - (Optional) The MAC address for the container to use (e.g.
   185    "02:68:b3:29:da:98").
   186  
   187  * `network_aliases` - (Optional) A list of network-scoped aliases, provide a way for a
   188    container to be discovered by an alternate name by any other container within
   189    the scope of a particular network. Network-scoped alias is supported only for
   190    containers in user defined networks
   191  
   192      ```hcl
   193      config {
   194        network_mode = "user-network"
   195        network_aliases = [
   196          "${NOMAD_TASK_NAME}",
   197          "${NOMAD_TASK_NAME}-${NOMAD_ALLOC_INDEX}"
   198        ]
   199      }
   200      ```
   201  
   202  * `network_mode` - (Optional) The network mode to be used for the container. In
   203    order to support userspace networking plugins in Docker 1.9 this accepts any
   204    value. The default is `bridge` for all operating systems but Windows, which
   205    defaults to `nat`. Other networking modes may not work without additional
   206    configuration on the host (which is outside the scope of Nomad).  Valid values
   207    pre-docker 1.9 are `default`, `bridge`, `host`, `none`, or `container:name`.
   208  
   209  * `pid_mode` - (Optional) `host` or not set (default). Set to `host` to share
   210    the PID namespace with the host. Note that this also requires the Nomad agent
   211    to be configured to allow privileged containers.
   212    See below for more details.
   213  
   214  * `port_map` - (Optional) A key-value map of port labels (see below).
   215  
   216  * `security_opt` - (Optional) A list of string flags to pass directly to
   217    [`--security-opt`](https://docs.docker.com/engine/reference/run/#security-configuration).
   218    For example:
   219  
   220  
   221      ```hcl
   222      config {
   223        security_opt = [
   224          "credentialspec=file://gmsaUser.json",
   225        ]
   226      }
   227      ```
   228  
   229  * `shm_size` - (Optional) The size (bytes) of /dev/shm for the container.
   230  
   231  * `storage_opt` - (Optional) A key-value map of storage options set to the containers on start.
   232    This overrides the [host dockerd configuration](https://docs.docker.com/engine/reference/commandline/dockerd/#options-per-storage-driver).
   233    For example:
   234  
   235  
   236      ```hcl
   237      config {
   238        storage_opt = {
   239          size = "40G"
   240        }
   241      }
   242      ```
   243  
   244  * `SSL` - (Optional) If this is set to true, Nomad uses SSL to talk to the
   245    repository. The default value is `true`. **Deprecated as of 0.5.3**
   246  
   247  * `tty` - (Optional) `true` or `false` (default). Allocate a pseudo-TTY for the
   248    container.
   249  
   250  * `uts_mode` - (Optional) `host` or not set (default). Set to `host` to share
   251    the UTS namespace with the host. Note that this also requires the Nomad agent
   252    to be configured to allow privileged containers.
   253  
   254  * `userns_mode` - (Optional) `host` or not set (default). Set to `host` to use
   255    the host's user namespace when user namespace remapping is enabled on the
   256    docker daemon.
   257  
   258  * `volumes` - (Optional) A list of `host_path:container_path` strings to bind
   259    host paths to container paths. Mounting host paths outside of the allocation
   260    directory can be disabled on clients by setting the `docker.volumes.enabled`
   261    option set to false. This will limit volumes to directories that exist inside
   262    the allocation directory. We recommend using [`mounts`](#mounts) if you wish
   263    to have more control over volume definitions.
   264  
   265      ```hcl
   266      config {
   267        volumes = [
   268          # Use absolute paths to mount arbitrary paths on the host
   269          "/path/on/host:/path/in/container",
   270  
   271          # Use relative paths to rebind paths already in the allocation dir
   272          "relative/to/task:/also/in/container"
   273        ]
   274      }
   275      ```
   276  
   277  * `volume_driver` - (Optional) The name of the volume driver used to mount
   278    volumes. Must be used along with `volumes`. If `volume_driver` is omitted,
   279    then relative paths will be mounted from inside the allocation dir. If a
   280    `"local"` or other driver is used, then they may be named volumes instead.
   281    If `docker.volumes.enabled` is false then volume drivers and paths outside the
   282    allocation directory are disallowed.
   283  
   284      ```hcl
   285      config {
   286        volumes = [
   287          # Use named volume created outside nomad.
   288          "name-of-the-volume:/path/in/container"
   289        ]
   290        # Name of the Docker Volume Driver used by the container
   291        volume_driver = "pxd"
   292      }
   293      ```
   294  
   295  * `work_dir` - (Optional) The working directory inside the container.
   296  
   297  * `mounts` - (Optional) A list of
   298    [mounts](https://docs.docker.com/engine/reference/commandline/service_create/#add-bind-mounts-or-volumes)
   299    to be mounted into the container. Volume, bind, and tmpfs type mounts are supported.
   300  
   301      ```hcl
   302      config {
   303        mounts = [
   304          # sample volume mount
   305          {
   306            type = "volume"
   307            target = "/path/in/container"
   308            source = "name-of-volume"
   309            readonly = false
   310            volume_options {
   311              no_copy = false
   312              labels {
   313                foo = "bar"
   314              }
   315              driver_config {
   316                name = "pxd"
   317                options = {
   318                  foo = "bar"
   319                }
   320              }
   321            }
   322          },
   323          # sample bind mount
   324          {
   325            type = "bind"
   326            target = "/path/in/container"
   327            source = "/path/in/host"
   328            readonly = false
   329            bind_options {
   330              propagation = "rshared"
   331            }
   332          },
   333          # sample tmpfs mount
   334          {
   335            type = "tmpfs"
   336            target = "/path/in/container"
   337            readonly = false
   338            tmpfs_options {
   339              size = 100000 # size in bytes
   340            }
   341          }
   342        ]
   343      }
   344      ```
   345  * `devices` - (Optional) A list of
   346    [devices](https://docs.docker.com/engine/reference/commandline/run/#add-host-device-to-container-device)
   347    to be exposed the container. `host_path` is the only required field. By default, the container will be able to
   348    `read`, `write` and `mknod` these devices. Use the optional `cgroup_permissions` field to restrict permissions.
   349  
   350      ```hcl
   351      config {
   352        devices = [
   353          {
   354            host_path = "/dev/sda1"
   355            container_path = "/dev/xvdc"
   356            cgroup_permissions = "r"
   357          },
   358          {
   359            host_path = "/dev/sda2"
   360            container_path = "/dev/xvdd"
   361          }
   362        ]
   363      }
   364      ```
   365  
   366  * `cap_add` - (Optional) A list of Linux capabilities as strings to pass directly to
   367    [`--cap-add`](https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities).
   368    Effective capabilities (computed from `cap_add` and `cap_drop`) have to match the configured whitelist.
   369    The whitelist can be customized using the [`allow_caps`](#plugin_caps) plugin option key in the client node's configuration.
   370    For example:
   371  
   372  
   373      ```hcl
   374      config {
   375        cap_add = [
   376          "SYS_TIME",
   377        ]
   378      }
   379      ```
   380  
   381  * `cap_drop` - (Optional) A list of Linux capabilities as strings to pass directly to
   382    [`--cap-drop`](https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities).
   383    Effective capabilities (computed from `cap_add` and `cap_drop`) have to match the configured whitelist.
   384    The whitelist can be customized using the [`allow_caps`](#plugin_caps) plugin option key in the client node's configuration.
   385    For example:
   386  
   387  
   388      ```hcl
   389      config {
   390        cap_drop = [
   391          "MKNOD",
   392        ]
   393      }
   394      ```
   395  
   396  * `cpu_hard_limit` - (Optional) `true` or `false` (default). Use hard CPU
   397    limiting instead of soft limiting. By default this is `false` which means
   398    soft limiting is used and containers are able to burst above their CPU limit
   399    when there is idle capacity.
   400  
   401  * `cpu_cfs_period` - (Optional) An integer value that specifies the duration in microseconds of the period
   402    during which the CPU usage quota is measured. The default is 100000 (0.1 second) and the maximum allowed
   403    value is 1000000 (1 second). See [here](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/resource_management_guide/sec-cpu#sect-cfs)
   404    for more details.
   405  
   406  * `advertise_ipv6_address` - (Optional) `true` or `false` (default). Use the container's
   407     IPv6 address (GlobalIPv6Address in Docker) when registering services and checks.
   408     See [IPv6 Docker containers](/docs/job-specification/service.html#IPv6 Docker containers) for details.
   409  
   410  * `readonly_rootfs` - (Optional) `true` or `false` (default). Mount
   411    the container's filesystem as read only.
   412  
   413  * `pids_limit` - (Optional) An integer value that specifies the pid limit for
   414    the container. Defaults to unlimited.
   415  
   416  ### Container Name
   417  
   418  Nomad creates a container after pulling an image. Containers are named
   419  `{taskName}-{allocId}`. This is necessary in order to place more than one
   420  container from the same task on a host (e.g. with count > 1). This also means
   421  that each container's name is unique across the cluster.
   422  
   423  This is not configurable.
   424  
   425  ### Authentication
   426  
   427  If you want to pull from a private repo (for example on dockerhub or quay.io),
   428  you will need to specify credentials in your job via:
   429  
   430   * the `auth` option in the task config.
   431  
   432   * by storing explicit repository credentials or by specifying Docker
   433     `credHelpers` in a file and setting the auth [config](#plugin_auth_file)
   434     value on the client in the plugin options.
   435  
   436   * by specifying an auth [helper](#plugin_auth_helper) on the client in the
   437     plugin options.
   438  
   439  The `auth` object supports the following keys:
   440  
   441  * `username` - (Optional) The account username.
   442  
   443  * `password` - (Optional) The account password.
   444  
   445  * `email` - (Optional) The account email.
   446  
   447  * `server_address` - (Optional) The server domain/IP without the protocol.
   448    Docker Hub is used by default.
   449  
   450  Example task-config:
   451  
   452  ```hcl
   453  task "example" {
   454    driver = "docker"
   455  
   456    config {
   457      image = "secret/service"
   458  
   459      auth {
   460        username = "dockerhub_user"
   461        password = "dockerhub_password"
   462      }
   463    }
   464  }
   465  ```
   466  
   467  Example docker-config, using two helper scripts in $PATH,
   468  "docker-credential-ecr" and "docker-credential-vault":
   469  
   470  ```json
   471  {
   472    "auths": {
   473      "internal.repo": { "auth": "`echo -n '<username>:<password>' | base64 -w0`" }
   474    },
   475    "credHelpers": {
   476        "<XYZ>.dkr.ecr.<region>.amazonaws.com": "ecr-login"
   477    },
   478    "credsStore": "secretservice"
   479  }
   480  ```
   481  
   482  Example agent configuration, using a helper script "docker-credential-ecr" in
   483  $PATH
   484  
   485  ```hcl
   486  client {
   487    enabled = true
   488  }
   489  
   490  plugin "docker" {
   491    config {
   492      auth {
   493        helper = "docker-credential-ecr"
   494      }
   495    }
   496  }
   497  ```
   498  !> **Be Careful!** At this time these credentials are stored in Nomad in plain
   499  text. Secrets management will be added in a later release.
   500  
   501  ## Networking
   502  
   503  Docker supports a variety of networking configurations, including using host
   504  interfaces, SDNs, etc. Nomad uses `bridged` networking by default, like Docker.
   505  
   506  You can specify other networking options, including custom networking plugins
   507  in Docker 1.9. **You may need to perform additional configuration on the host
   508  in order to make these work.** This additional configuration is outside the
   509  scope of Nomad.
   510  
   511  ### Allocating Ports
   512  
   513  You can allocate ports to your task using the port syntax described on the
   514  [networking page](/docs/job-specification/network.html). Here is a recap:
   515  
   516  ```hcl
   517  task "example" {
   518    driver = "docker"
   519  
   520    resources {
   521      network {
   522        port "http" {}
   523        port "https" {}
   524      }
   525    }
   526  }
   527  ```
   528  
   529  ### Forwarding and Exposing Ports
   530  
   531  A Docker container typically specifies which port a service will listen on by
   532  specifying the `EXPOSE` directive in the `Dockerfile`.
   533  
   534  Because dynamic ports will not match the ports exposed in your Dockerfile,
   535  Nomad will automatically expose all of the ports it allocates to your
   536  container.
   537  
   538  These ports will be identified via environment variables. For example:
   539  
   540  ```hcl
   541  port "http" {}
   542  ```
   543  
   544  If Nomad allocates port `23332` to your task for `http`, `23332` will be
   545  automatically exposed and forwarded to your container, and the driver will set
   546  an environment variable `NOMAD_PORT_http` with the value `23332` that you can
   547  read inside your container.
   548  
   549  This provides an easy way to use the `host` networking option for better
   550  performance.
   551  
   552  ### Using the Port Map
   553  
   554  If you prefer to use the traditional port-mapping method, you can specify the
   555  `port_map` option in your job specification. It looks like this:
   556  
   557  ```hcl
   558  task "example" {
   559    driver = "docker"
   560  
   561    config {
   562      image = "redis"
   563  
   564      port_map {
   565        redis = 6379
   566      }
   567    }
   568  
   569    resources {
   570      network {
   571        mbits = 20
   572        port "redis" {}
   573      }
   574    }
   575  }
   576  ```
   577  
   578  If Nomad allocates port `23332` to your task, the Docker driver will
   579  automatically setup the port mapping from `23332` on the host to `6379` in your
   580  container, so it will just work!
   581  
   582  Note that by default this only works with `bridged` networking mode. It may
   583  also work with custom networking plugins which implement the same API for
   584  expose and port forwarding.
   585  
   586  ### Advertising Container IPs
   587  
   588  *New in Nomad 0.6.*
   589  
   590  When using network plugins like `weave` that assign containers a routable IP
   591  address, that address will automatically be used in any `service`
   592  advertisements for the task. You may override what address is advertised by
   593  using the `address_mode` parameter on a `service`. See
   594  [service](/docs/job-specification/service.html) for details.
   595  
   596  ### Networking Protocols
   597  
   598  The Docker driver configures ports on both the `tcp` and `udp` protocols.
   599  
   600  This is not configurable.
   601  
   602  ### Other Networking Modes
   603  
   604  Some networking modes like `container` or `none` will require coordination
   605  outside of Nomad. First-class support for these options may be improved later
   606  through Nomad plugins or dynamic job configuration.
   607  
   608  ## Client Requirements
   609  
   610  Nomad requires Docker to be installed and running on the host alongside the
   611  Nomad agent. Nomad was developed against Docker `1.8.2` and `1.9`.
   612  
   613  By default Nomad communicates with the Docker daemon using the daemon's Unix
   614  socket. Nomad will need to be able to read/write to this socket. If you do not
   615  run Nomad as root, make sure you add the Nomad user to the Docker group so
   616  Nomad can communicate with the Docker daemon.
   617  
   618  For example, on Ubuntu you can use the `usermod` command to add the `vagrant`
   619  user to the `docker` group so you can run Nomad without root:
   620  
   621      sudo usermod -G docker -a vagrant
   622  
   623  For the best performance and security features you should use recent versions
   624  of the Linux Kernel and Docker daemon.
   625  
   626  If you would like to change any of the options related to the `docker` driver on
   627  a Nomad client, you can modify them with the [plugin stanza][plugin-stanza] syntax. Below is an example of a configuration (many of the values are the default). See the next section for more information on the options.
   628  
   629  ```hcl
   630  plugin "docker" {
   631    config {
   632      endpoint = "unix:///var/run/docker.sock"
   633  
   634      auth {
   635        config = "/etc/docker-auth.json"
   636        helper = "docker-credential-aws"
   637      }
   638  
   639      tls {
   640        cert = "/etc/nomad/nomad.pub"
   641        key  = "/etc/nomad/nomad.pem"
   642        ca   = "/etc/nomad/nomad.cert"
   643      }
   644  
   645      gc {
   646        image       = true
   647        image_delay = "3m"
   648        container   = true
   649      }
   650  
   651      volumes {
   652        enabled      = true
   653        selinuxlabel = "z"
   654      }
   655  
   656      allow_privileged = false
   657      allow_caps       = ["CHOWN", "NET_RAW"]
   658  
   659      # allow_caps can also be set to "ALL"
   660      # allow_caps = ["ALL"]
   661    }
   662  }
   663  ```
   664  ## Plugin Options
   665  
   666  * `endpoint` - If using a non-standard socket, HTTP or another location, or if
   667    TLS is being used, docker.endpoint must be set. If unset, Nomad will attempt
   668    to instantiate a Docker client using the DOCKER_HOST environment variable and
   669    then fall back to the default listen address for the given operating system.
   670    Defaults to unix:///var/run/docker.sock on Unix platforms and
   671    npipe:////./pipe/docker_engine for Windows.
   672  
   673  * `allow_privileged` - Defaults to `false`. Changing this to true will allow
   674    containers to use privileged mode, which gives the containers full access to
   675    the host's devices. Note that you must set a similar setting on the Docker
   676    daemon for this to work.
   677  
   678  * `allow_caps`<a id="plugin_caps"></a> - A list of allowed Linux capabilities.
   679    Defaults to
   680    "CHOWN,DAC_OVERRIDE,FSETID,FOWNER,MKNOD,NET_RAW,SETGID,SETUID,SETFCAP,SETPCAP,
   681    NET_BIND_SERVICE,SYS_CHROOT,KILL,AUDIT_WRITE", which is the list of
   682    capabilities allowed by docker by default, as defined here. Allows the
   683    operator to control which capabilities can be obtained by tasks using cap_add
   684    and cap_drop options. Supports the value "ALL" as a shortcut for whitelisting
   685    all capabilities.
   686  
   687  * `auth` stanza:
   688      * `config`<a id="plugin_auth_file"></a> - Allows an operator to specify a
   689        JSON file which is in the dockercfg format containing authentication
   690        information for a private registry, from either (in order) `auths`,
   691        `credHelpers` or `credsStore`. 
   692      * `helper`<a id="plugin_auth_helper"></a> - Allows an operator to specify a
   693        [credsStore](https://docs.docker.com/engine/reference/commandline/login/#credential-helper-protocol)
   694        -like script on $PATH to lookup authentication information from external
   695        sources. The script's name must begin with `docker-credential-` and this
   696        option should include only the basename of the script, not the path.
   697  
   698  * `tls` stanza:
   699      * `cert` - Path to the server's certificate file (`.pem`). Specify this
   700        along with `key` and `ca` to use a TLS client to connect to the docker
   701        daemon. `endpoint` must also be specified or this setting will be ignored.
   702      * `key` - Path to the client's private key (`.pem`). Specify this along with
   703        `cert` and `ca` to use a TLS client to connect to the docker daemon.
   704        `endpoint` must also be specified or this setting will be ignored.
   705      * `ca` - Path to the server's CA file (`.pem`). Specify this along with
   706        `cert` and `key` to use a TLS client to connect to the docker daemon.
   707        `endpoint` must also be specified or this setting will be ignored.
   708  
   709  * `gc` stanza:
   710      * `image` - Defaults to `true`. Changing this to `false` will prevent Nomad
   711        from removing images from stopped tasks.
   712      * `image_delay` - A time duration, as [defined
   713        here](https://golang.org/pkg/time/#ParseDuration), that defaults to `3m`.
   714        The delay controls how long Nomad will wait between an image being unused
   715        and deleting it. If a tasks is received that uses the same image within
   716        the delay, the image will be reused.
   717      * `container` - Defaults to `true`. This option can be used to disable Nomad
   718        from removing a container when the task exits. Under a name conflict,
   719        Nomad may still remove the dead container.
   720  
   721  * `volumes` stanza:
   722      * `enabled` - Defaults to `true`. Allows tasks to bind host paths
   723        (`volumes`) inside their container and use volume drivers
   724        (`volume_driver`). Binding relative paths is always allowed and will be
   725        resolved relative to the allocation's directory.
   726      * `selinuxlabel` - Allows the operator to set a SELinux label to the
   727        allocation and task local bind-mounts to containers. If used with
   728        `docker.volumes.enabled` set to false, the labels will still be applied to
   729        the standard binds in the container.
   730  
   731  ## Client Configuration
   732  
   733  ~> Note: client configuration options will soon be deprecated. Please use
   734  [plugin options][plugin-options] instead. See the [plugin stanza][plugin-stanza]
   735  documentation for more information.
   736  
   737  The `docker` driver has the following [client configuration
   738  options](/docs/configuration/client.html#options):
   739  
   740  * `docker.endpoint` - If using a non-standard socket, HTTP or another location,
   741    or if TLS is being used, `docker.endpoint` must be set. If unset, Nomad will
   742    attempt to instantiate a Docker client using the `DOCKER_HOST` environment
   743    variable and then fall back to the default listen address for the given
   744    operating system. Defaults to `unix:///var/run/docker.sock` on Unix platforms
   745    and `npipe:////./pipe/docker_engine` for Windows.
   746  
   747  * `docker.auth.config` <a id="auth_file"></a>- Allows an operator to specify a
   748    JSON file which is in the dockercfg format containing authentication
   749    information for a private registry, from either (in order) `auths`,
   750    `credHelpers` or `credsStore`.
   751  
   752  * `docker.auth.helper` <a id="auth_helper"></a>- Allows an operator to specify a
   753    [credsStore](https://docs.docker.com/engine/reference/commandline/login/#credential-helper-protocol)
   754    -like script on $PATH to lookup authentication information from external
   755    sources. The script's name must begin with `docker-credential-` and this
   756    option should include only the basename of the script, not the path.
   757  
   758  * `docker.tls.cert` - Path to the server's certificate file (`.pem`). Specify
   759    this along with `docker.tls.key` and `docker.tls.ca` to use a TLS client to
   760    connect to the docker daemon. `docker.endpoint` must also be specified or this
   761    setting will be ignored.
   762  
   763  * `docker.tls.key` - Path to the client's private key (`.pem`). Specify this
   764    along with `docker.tls.cert` and `docker.tls.ca` to use a TLS client to
   765    connect to the docker daemon. `docker.endpoint` must also be specified or this
   766    setting will be ignored.
   767  
   768  * `docker.tls.ca` - Path to the server's CA file (`.pem`). Specify this along
   769    with `docker.tls.cert` and `docker.tls.key` to use a TLS client to connect to
   770    the docker daemon. `docker.endpoint` must also be specified or this setting
   771    will be ignored.
   772  
   773  * `docker.cleanup.image` Defaults to `true`. Changing this to `false` will
   774    prevent Nomad from removing images from stopped tasks.
   775  
   776  * `docker.cleanup.image.delay` A time duration, as [defined
   777    here](https://golang.org/pkg/time/#ParseDuration), that defaults to `3m`. The
   778    delay controls how long Nomad will wait between an image being unused and
   779    deleting it. If a tasks is received that uses the same image within the delay,
   780    the image will be reused.
   781  
   782  * `docker.volumes.enabled`: Defaults to `true`. Allows tasks to bind host paths
   783    (`volumes`) inside their container and use volume drivers (`volume_driver`).
   784    Binding relative paths is always allowed and will be resolved relative to the
   785    allocation's directory.
   786  
   787  * `docker.volumes.selinuxlabel`: Allows the operator to set a SELinux label to
   788    the allocation and task local bind-mounts to containers. If used with
   789    `docker.volumes.enabled` set to false, the labels will still be applied to the
   790    standard binds in the container.
   791  
   792  * `docker.privileged.enabled` Defaults to `false`. Changing this to `true` will
   793    allow containers to use `privileged` mode, which gives the containers full
   794    access to the host's devices. Note that you must set a similar setting on the
   795    Docker daemon for this to work.
   796  
   797  * `docker.caps.whitelist`: A list of allowed Linux capabilities. Defaults to
   798    `"CHOWN,DAC_OVERRIDE,FSETID,FOWNER,MKNOD,NET_RAW,SETGID,SETUID,SETFCAP,
   799    SETPCAP,NET_BIND_SERVICE,SYS_CHROOT,KILL,AUDIT_WRITE"`, which is the list of
   800    capabilities allowed by docker by default, as [defined
   801    here](https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities).
   802    Allows the operator to control which capabilities can be obtained by tasks
   803    using `cap_add` and `cap_drop` options. Supports the value `"ALL"` as a
   804    shortcut for whitelisting all capabilities.
   805  
   806  * `docker.cleanup.container`: Defaults to `true`. This option can be used to
   807    disable Nomad from removing a container when the task exits. Under a name
   808    conflict, Nomad may still remove the dead container.
   809  
   810  * `docker.nvidia_runtime`: Defaults to `nvidia`. This option allows operators to select the runtime that should be used in order to expose Nvidia GPUs to the container.
   811  
   812  Note: When testing or using the `-dev` flag you can use `DOCKER_HOST`,
   813  `DOCKER_TLS_VERIFY`, and `DOCKER_CERT_PATH` to customize Nomad's behavior. If
   814  `docker.endpoint` is set Nomad will **only** read client configuration from the
   815  config file.
   816  
   817  An example is given below:
   818  
   819  ```hcl
   820  client {
   821    options {
   822      "docker.cleanup.image" = "false"
   823    }
   824  }
   825  ```
   826  
   827  ## Client Attributes
   828  
   829  The `docker` driver will set the following client attributes:
   830  
   831  * `driver.docker` - This will be set to "1", indicating the driver is
   832    available.
   833  * `driver.docker.bridge_ip` - The IP of the Docker bridge network if one
   834    exists.
   835  * `driver.docker.version` - This will be set to version of the docker server.
   836  
   837  Here is an example of using these properties in a job file:
   838  
   839  ```hcl
   840  job "docs" {
   841    # Require docker version higher than 1.2.
   842    constraint {
   843      attribute = "${driver.docker.version}"
   844      operator  = ">"
   845      version   = "1.2"
   846    }
   847  }
   848  ```
   849  
   850  ## Resource Isolation
   851  
   852  ### CPU
   853  
   854  Nomad limits containers' CPU based on CPU shares. CPU shares allow containers
   855  to burst past their CPU limits. CPU limits will only be imposed when there is
   856  contention for resources. When the host is under load your process may be
   857  throttled to stabilize QoS depending on how many shares it has. You can see how
   858  many CPU shares are available to your process by reading `NOMAD_CPU_LIMIT`.
   859  1000 shares are approximately equal to 1 GHz.
   860  
   861  Please keep the implications of CPU shares in mind when you load test workloads
   862  on Nomad.
   863  
   864  ### Memory
   865  
   866  Nomad limits containers' memory usage based on total virtual memory. This means
   867  that containers scheduled by Nomad cannot use swap. This is to ensure that a
   868  swappy process does not degrade performance for other workloads on the same
   869  host.
   870  
   871  Since memory is not an elastic resource, you will need to make sure your
   872  container does not exceed the amount of memory allocated to it, or it will be
   873  terminated or crash when it tries to malloc. A process can inspect its memory
   874  limit by reading `NOMAD_MEMORY_LIMIT`, but will need to track its own memory
   875  usage. Memory limit is expressed in megabytes so 1024 = 1 GB.
   876  
   877  ### IO
   878  
   879  Nomad's Docker integration does not currently provide QoS around network or
   880  filesystem IO. These will be added in a later release.
   881  
   882  ### Security
   883  
   884  Docker provides resource isolation by way of
   885  [cgroups and namespaces](https://docs.docker.com/introduction/understanding-docker/#the-underlying-technology).
   886  Containers essentially have a virtual file system all to themselves. If you
   887  need a higher degree of isolation between processes for security or other
   888  reasons, it is recommended to use full virtualization like
   889  [QEMU](/docs/drivers/qemu.html).
   890  
   891  ## Docker for Windows Caveats
   892  
   893  Docker for Windows only supports running Windows containers. Because Docker for
   894  Windows is relatively new and rapidly evolving you may want to consult the
   895  [list of relevant issues on GitHub][WinIssues].
   896  
   897  [WinIssues]: https://github.com/hashicorp/nomad/issues?q=is%3Aopen+is%3Aissue+label%3Adriver%2Fdocker+label%3Aplatform-windows
   898  [plugin-options]: #plugin-options
   899  [plugin-stanza]: /docs/configuration/plugin.html