github.com/jmitchell/nomad@v0.1.3-0.20151007230021-7ab84c2862d8/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 The `docker` driver supports the following configuration in the job specification: 20 21 * `image` - (Required) The Docker image to run. The image may include a tag or 22 custom URL. By default it will be fetched from Docker Hub. 23 24 * `command` - (Optional) The command to run when starting the container. 25 26 * `network_mode` - (Optional) The network mode to be used for the container. 27 Valid options are `default`, `bridge`, `host` or `none`. If nothing is 28 specified, the container will start in `bridge` mode. The `container` 29 network mode is not supported right now. 30 31 ### Port Mapping 32 33 Nomad uses port binding to expose services running in containers using the port 34 space on the host's interface. For example, Nomad host running on `1.2.3.4` may 35 allocate port `22333` to a task, so you would access that service via 36 `1.2.3.4:22333`. 37 38 Nomad provides automatic and manual mapping schemes for Docker. You can use 39 either or both schemes for a task. Nomad binds both tcp and udp protocols to 40 ports used for Docker containers. This is not configurable. 41 42 Note: You are not required to map any ports, for example if your task is running 43 a crawler or aggregator and does not provide a network service. Tasks without a 44 port mapping will still be able to make outbound network connections. 45 46 #### Automatic Port Mapping 47 48 Typically when you create a Docker container you configure the service to start 49 listening on a port (or ports) when you start the container. For example, redis 50 starts listening on `6379` when you `Docker run redis`. Nomad supports this by 51 mapping the random port to the port inside the container. 52 53 You need to tell Nomad which ports your container is using so Nomad can map 54 allocated ports for you. You do so by specifying a **numeric port value** for 55 the `dynamic_ports` option in your job specification. 56 57 ``` 58 dynamic_ports = ["6379"] 59 # or 60 dynamic_ports = [6379] 61 ``` 62 63 This instructs Nomad to create a port mapping from the random port on the host 64 to the port inside the container. So in our example above, when you contact the 65 host on `1.2.3.4:22333` you will actually hit the service running inside the 66 container on port `6379`. You can see which port was actually bound by reading the 67 `NOMAD_PORT_6379` [environment variable](/docs/jobspec/environment.html). 68 69 In most cases, the automatic port mapping will be the easiest to use, but you 70 can also use manual port mapping (described below). 71 72 #### Manual Port Mapping 73 74 The `dynamic_ports` option takes any alphanumeric string as a label, so you could 75 also specify a label for the port like `http` or `admin` to designate how the 76 port will be used. 77 78 In this case, Nomad doesn't know which container port to map to, so it maps 1:1 79 with the host port. For example, `1.2.3.4:22333` will map to `22333` inside the 80 container. 81 82 ``` 83 dynamic_ports = ["http"] 84 ``` 85 86 Your process will need to read the `NOMAD_PORT_HTTP` environment variable to 87 determine which port to bind to. 88 89 ## Client Requirements 90 91 Nomad requires Docker to be installed and running on the host alongside the Nomad 92 agent. Nomad was developed against Docker `1.8.2`. 93 94 By default Nomad communicates with the Docker daemon using the daemon's 95 unix socket. Nomad will need to be able to read/write to this socket. If you do 96 not run Nomad as root, make sure you add the Nomad user to the Docker group so 97 Nomad can communicate with the Docker daemon. 98 99 For example, on ubuntu you can use the `usermod` command to add the `vagrant` user to the 100 `docker` group so you can run Nomad without root: 101 102 sudo usermod -G docker -a vagrant 103 104 For the best performance and security features you should use recent versions of 105 the Linux Kernel and Docker daemon. 106 107 ## Client Configuration 108 109 The `docker` driver has the following configuration options: 110 111 * `docker.endpoint` - Defaults to `unix:///var/run/docker.sock`. You will need 112 to customize this if you use a non-standard socket (http or another location). 113 114 ## Client Attributes 115 116 The `docker` driver will set the following client attributes: 117 118 * `driver.Docker` - This will be set to "1", indicating the 119 driver is available. 120 121 ## Resource Isolation 122 123 ### CPU 124 125 Nomad limits containers' CPU based on CPU shares. CPU shares allow containers to 126 burst past their CPU limits. CPU limits will only be imposed when there is 127 contention for resources. When the host is under load your process may be 128 throttled to stabilize QOS depending how how many shares it has. You can see how 129 many CPU shares are available to your process by reading `NOMAD_CPU_LIMIT`. 1000 130 shares are approximately equal to 1Ghz. 131 132 Please keep the implications of CPU shares in mind when you load test workloads 133 on Nomad. 134 135 ### Memory 136 137 Nomad limits containers' memory usage based on total virtual memory. This means 138 that containers scheduled by Nomad cannot use swap. This is to ensure that a 139 swappy process does not degrade performance for other workloads on the same host. 140 141 Since memory is not an elastic resource, you will need to make sure your 142 container does not exceed the amount of memory allocated to it, or it will be 143 terminated or crash when it tries to malloc. A process can inspect its memory 144 limit by reading `NOMAD_MEMORY_LIMIT`, but will need to track its own memory 145 usage. Memory limit is expressed in megabytes so 1024 = 1Gb. 146 147 ### IO 148 149 Nomad's Docker integration does not currently provide QOS around network or 150 filesystem IO. These will be added in a later release. 151 152 ### Security 153 154 Docker provides resource isolation by way of 155 [cgroups and namespaces](https://docs.docker.com/introduction/understanding-docker/#the-underlying-technology). 156 Containers essentially have a virtual file system all to themselves. If you need 157 a higher degree of isolation between processes for security or other reasons, it 158 is recommended to use full virtualization like [QEMU](/docs/drivers/qemu.html).