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