github.com/vieux/docker@v0.6.3-0.20161004191708-e097c2a938c7/docs/reference/api/docker_remote_api_v1.21.md (about) 1 <!--[metadata]> 2 +++ 3 title = "Remote API v1.21" 4 description = "API Documentation for Docker" 5 keywords = ["API, Docker, rcli, REST, documentation"] 6 [menu.main] 7 parent="engine_remoteapi" 8 weight=-2 9 +++ 10 <![end-metadata]--> 11 12 # Docker Remote API v1.21 13 14 ## 1. Brief introduction 15 16 - The Remote API has replaced `rcli`. 17 - The daemon listens on `unix:///var/run/docker.sock` but you can 18 [Bind Docker to another host/port or a Unix socket](../commandline/dockerd.md#bind-docker-to-another-host-port-or-a-unix-socket). 19 - The API tends to be REST. However, for some complex commands, like `attach` 20 or `pull`, the HTTP connection is hijacked to transport `stdout`, 21 `stdin` and `stderr`. 22 - When the client API version is newer than the daemon's, these calls return an HTTP 23 `400 Bad Request` error message. 24 25 # 2. Endpoints 26 27 ## 2.1 Containers 28 29 ### List containers 30 31 `GET /containers/json` 32 33 List containers 34 35 **Example request**: 36 37 GET /containers/json?all=1&before=8dfafdbc3a40&size=1 HTTP/1.1 38 39 **Example response**: 40 41 HTTP/1.1 200 OK 42 Content-Type: application/json 43 44 [ 45 { 46 "Id": "8dfafdbc3a40", 47 "Names":["/boring_feynman"], 48 "Image": "ubuntu:latest", 49 "ImageID": "d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82", 50 "Command": "echo 1", 51 "Created": 1367854155, 52 "Status": "Exit 0", 53 "Ports": [{"PrivatePort": 2222, "PublicPort": 3333, "Type": "tcp"}], 54 "Labels": { 55 "com.example.vendor": "Acme", 56 "com.example.license": "GPL", 57 "com.example.version": "1.0" 58 }, 59 "SizeRw": 12288, 60 "SizeRootFs": 0 61 }, 62 { 63 "Id": "9cd87474be90", 64 "Names":["/coolName"], 65 "Image": "ubuntu:latest", 66 "ImageID": "d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82", 67 "Command": "echo 222222", 68 "Created": 1367854155, 69 "Status": "Exit 0", 70 "Ports": [], 71 "Labels": {}, 72 "SizeRw": 12288, 73 "SizeRootFs": 0 74 }, 75 { 76 "Id": "3176a2479c92", 77 "Names":["/sleepy_dog"], 78 "Image": "ubuntu:latest", 79 "ImageID": "d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82", 80 "Command": "echo 3333333333333333", 81 "Created": 1367854154, 82 "Status": "Exit 0", 83 "Ports":[], 84 "Labels": {}, 85 "SizeRw":12288, 86 "SizeRootFs":0 87 }, 88 { 89 "Id": "4cb07b47f9fb", 90 "Names":["/running_cat"], 91 "Image": "ubuntu:latest", 92 "ImageID": "d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82", 93 "Command": "echo 444444444444444444444444444444444", 94 "Created": 1367854152, 95 "Status": "Exit 0", 96 "Ports": [], 97 "Labels": {}, 98 "SizeRw": 12288, 99 "SizeRootFs": 0 100 } 101 ] 102 103 **Query parameters**: 104 105 - **all** – 1/True/true or 0/False/false, Show all containers. 106 Only running containers are shown by default (i.e., this defaults to false) 107 - **limit** – Show `limit` last created 108 containers, include non-running ones. 109 - **since** – Show only containers created since Id, include 110 non-running ones. 111 - **before** – Show only containers created before Id, include 112 non-running ones. 113 - **size** – 1/True/true or 0/False/false, Show the containers 114 sizes 115 - **filters** - a JSON encoded value of the filters (a `map[string][]string`) to process on the containers list. Available filters: 116 - `exited=<int>`; -- containers with exit code of `<int>` ; 117 - `status=`(`created`|`restarting`|`running`|`paused`|`exited`) 118 - `label=key` or `label="key=value"` of a container label 119 120 **Status codes**: 121 122 - **200** – no error 123 - **400** – bad parameter 124 - **500** – server error 125 126 ### Create a container 127 128 `POST /containers/create` 129 130 Create a container 131 132 **Example request**: 133 134 POST /containers/create HTTP/1.1 135 Content-Type: application/json 136 137 { 138 "Hostname": "", 139 "Domainname": "", 140 "User": "", 141 "AttachStdin": false, 142 "AttachStdout": true, 143 "AttachStderr": true, 144 "Tty": false, 145 "OpenStdin": false, 146 "StdinOnce": false, 147 "Env": [ 148 "FOO=bar", 149 "BAZ=quux" 150 ], 151 "Cmd": [ 152 "date" 153 ], 154 "Entrypoint": null, 155 "Image": "ubuntu", 156 "Labels": { 157 "com.example.vendor": "Acme", 158 "com.example.license": "GPL", 159 "com.example.version": "1.0" 160 }, 161 "Volumes": { 162 "/volumes/data": {} 163 }, 164 "WorkingDir": "", 165 "NetworkDisabled": false, 166 "MacAddress": "12:34:56:78:9a:bc", 167 "ExposedPorts": { 168 "22/tcp": {} 169 }, 170 "StopSignal": "SIGTERM", 171 "HostConfig": { 172 "Binds": ["/tmp:/tmp"], 173 "Links": ["redis3:redis"], 174 "LxcConf": {"lxc.utsname":"docker"}, 175 "Memory": 0, 176 "MemorySwap": 0, 177 "MemoryReservation": 0, 178 "KernelMemory": 0, 179 "CpuShares": 512, 180 "CpuPeriod": 100000, 181 "CpuQuota": 50000, 182 "CpusetCpus": "0,1", 183 "CpusetMems": "0,1", 184 "BlkioWeight": 300, 185 "MemorySwappiness": 60, 186 "OomKillDisable": false, 187 "PidMode": "", 188 "PortBindings": { "22/tcp": [{ "HostPort": "11022" }] }, 189 "PublishAllPorts": false, 190 "Privileged": false, 191 "ReadonlyRootfs": false, 192 "Dns": ["8.8.8.8"], 193 "DnsOptions": [""], 194 "DnsSearch": [""], 195 "ExtraHosts": null, 196 "VolumesFrom": ["parent", "other:ro"], 197 "CapAdd": ["NET_ADMIN"], 198 "CapDrop": ["MKNOD"], 199 "GroupAdd": ["newgroup"], 200 "RestartPolicy": { "Name": "", "MaximumRetryCount": 0 }, 201 "NetworkMode": "bridge", 202 "Devices": [], 203 "Ulimits": [{}], 204 "LogConfig": { "Type": "json-file", "Config": {} }, 205 "SecurityOpt": [], 206 "CgroupParent": "", 207 "VolumeDriver": "" 208 } 209 } 210 211 **Example response**: 212 213 HTTP/1.1 201 Created 214 Content-Type: application/json 215 216 { 217 "Id":"e90e34656806", 218 "Warnings":[] 219 } 220 221 **JSON parameters**: 222 223 - **Hostname** - A string value containing the hostname to use for the 224 container. 225 - **Domainname** - A string value containing the domain name to use 226 for the container. 227 - **User** - A string value specifying the user inside the container. 228 - **AttachStdin** - Boolean value, attaches to `stdin`. 229 - **AttachStdout** - Boolean value, attaches to `stdout`. 230 - **AttachStderr** - Boolean value, attaches to `stderr`. 231 - **Tty** - Boolean value, Attach standard streams to a `tty`, including `stdin` if it is not closed. 232 - **OpenStdin** - Boolean value, opens `stdin`, 233 - **StdinOnce** - Boolean value, close `stdin` after the 1 attached client disconnects. 234 - **Env** - A list of environment variables in the form of `["VAR=value"[,"VAR2=value2"]]` 235 - **Labels** - Adds a map of labels to a container. To specify a map: `{"key":"value"[,"key2":"value2"]}` 236 - **Cmd** - Command to run specified as a string or an array of strings. 237 - **Entrypoint** - Set the entry point for the container as a string or an array 238 of strings. 239 - **Image** - A string specifying the image name to use for the container. 240 - **Volumes** - An object mapping mount point paths (strings) inside the 241 container to empty objects. 242 - **WorkingDir** - A string specifying the working directory for commands to 243 run in. 244 - **NetworkDisabled** - Boolean value, when true disables networking for the 245 container 246 - **ExposedPorts** - An object mapping ports to an empty object in the form of: 247 `"ExposedPorts": { "<port>/<tcp|udp>: {}" }` 248 - **StopSignal** - Signal to stop a container as a string or unsigned integer. `SIGTERM` by default. 249 - **HostConfig** 250 - **Binds** – A list of volume bindings for this container. Each volume binding is a string in one of these forms: 251 + `host-src:container-dest` to bind-mount a host path into the 252 container. Both `host-src`, and `container-dest` must be an 253 _absolute_ path. 254 + `host-src:container-dest:ro` to make the bind-mount read-only 255 inside the container. Both `host-src`, and `container-dest` must be 256 an _absolute_ path. 257 + `volume-name:container-dest` to bind-mount a volume managed by a 258 volume driver into the container. `container-dest` must be an 259 _absolute_ path. 260 + `volume-name:container-dest:ro` to mount the volume read-only 261 inside the container. `container-dest` must be an _absolute_ path. 262 - **Links** - A list of links for the container. Each link entry should be 263 in the form of `container_name:alias`. 264 - **LxcConf** - LXC specific configurations. These configurations only 265 work when using the `lxc` execution driver. 266 - **Memory** - Memory limit in bytes. 267 - **MemorySwap** - Total memory limit (memory + swap); set `-1` to enable unlimited swap. 268 You must use this with `memory` and make the swap value larger than `memory`. 269 - **MemoryReservation** - Memory soft limit in bytes. 270 - **KernelMemory** - Kernel memory limit in bytes. 271 - **CpuShares** - An integer value containing the container's CPU Shares 272 (ie. the relative weight vs other containers). 273 - **CpuPeriod** - The length of a CPU period in microseconds. 274 - **CpuQuota** - Microseconds of CPU time that the container can get in a CPU period. 275 - **CpusetCpus** - String value containing the `cgroups CpusetCpus` to use. 276 - **CpusetMems** - Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems. 277 - **BlkioWeight** - Block IO weight (relative weight) accepts a weight value between 10 and 1000. 278 - **MemorySwappiness** - Tune a container's memory swappiness behavior. Accepts an integer between 0 and 100. 279 - **OomKillDisable** - Boolean value, whether to disable OOM Killer for the container or not. 280 - **PidMode** - Set the PID (Process) Namespace mode for the container; 281 `"container:<name|id>"`: joins another container's PID namespace 282 `"host"`: use the host's PID namespace inside the container 283 - **PortBindings** - A map of exposed container ports and the host port they 284 should map to. A JSON object in the form 285 `{ <port>/<protocol>: [{ "HostPort": "<port>" }] }` 286 Take note that `port` is specified as a string and not an integer value. 287 - **PublishAllPorts** - Allocates a random host port for all of a container's 288 exposed ports. Specified as a boolean value. 289 - **Privileged** - Gives the container full access to the host. Specified as 290 a boolean value. 291 - **ReadonlyRootfs** - Mount the container's root filesystem as read only. 292 Specified as a boolean value. 293 - **Dns** - A list of DNS servers for the container to use. 294 - **DnsOptions** - A list of DNS options 295 - **DnsSearch** - A list of DNS search domains 296 - **ExtraHosts** - A list of hostnames/IP mappings to add to the 297 container's `/etc/hosts` file. Specified in the form `["hostname:IP"]`. 298 - **VolumesFrom** - A list of volumes to inherit from another container. 299 Specified in the form `<container name>[:<ro|rw>]` 300 - **CapAdd** - A list of kernel capabilities to add to the container. 301 - **Capdrop** - A list of kernel capabilities to drop from the container. 302 - **GroupAdd** - A list of additional groups that the container process will run as 303 - **RestartPolicy** – The behavior to apply when the container exits. The 304 value is an object with a `Name` property of either `"always"` to 305 always restart, `"unless-stopped"` to restart always except when 306 user has manually stopped the container or `"on-failure"` to restart only when the container 307 exit code is non-zero. If `on-failure` is used, `MaximumRetryCount` 308 controls the number of times to retry before giving up. 309 The default is not to restart. (optional) 310 An ever increasing delay (double the previous delay, starting at 100mS) 311 is added before each restart to prevent flooding the server. 312 - **NetworkMode** - Sets the networking mode for the container. Supported 313 standard values are: `bridge`, `host`, `none`, and `container:<name|id>`. Any other value is taken 314 as a custom network's name to which this container should connect to. 315 - **Devices** - A list of devices to add to the container specified as a JSON object in the 316 form 317 `{ "PathOnHost": "/dev/deviceName", "PathInContainer": "/dev/deviceName", "CgroupPermissions": "mrw"}` 318 - **Ulimits** - A list of ulimits to set in the container, specified as 319 `{ "Name": <name>, "Soft": <soft limit>, "Hard": <hard limit> }`, for example: 320 `Ulimits: { "Name": "nofile", "Soft": 1024, "Hard": 2048 }` 321 - **SecurityOpt**: A list of string values to customize labels for MLS 322 systems, such as SELinux. 323 - **LogConfig** - Log configuration for the container, specified as a JSON object in the form 324 `{ "Type": "<driver_name>", "Config": {"key1": "val1"}}`. 325 Available types: `json-file`, `syslog`, `journald`, `gelf`, `awslogs`, `none`. 326 `json-file` logging driver. 327 - **CgroupParent** - Path to `cgroups` under which the container's `cgroup` is created. If the path is not absolute, the path is considered to be relative to the `cgroups` path of the init process. Cgroups are created if they do not already exist. 328 - **VolumeDriver** - Driver that this container users to mount volumes. 329 330 **Query parameters**: 331 332 - **name** – Assign the specified name to the container. Must 333 match `/?[a-zA-Z0-9_-]+`. 334 335 **Status codes**: 336 337 - **201** – no error 338 - **400** – bad parameter 339 - **404** – no such container 340 - **406** – impossible to attach (container not running) 341 - **409** – conflict 342 - **500** – server error 343 344 ### Inspect a container 345 346 `GET /containers/(id or name)/json` 347 348 Return low-level information on the container `id` 349 350 **Example request**: 351 352 GET /containers/4fa6e0f0c678/json HTTP/1.1 353 354 **Example response**: 355 356 HTTP/1.1 200 OK 357 Content-Type: application/json 358 359 { 360 "AppArmorProfile": "", 361 "Args": [ 362 "-c", 363 "exit 9" 364 ], 365 "Config": { 366 "AttachStderr": true, 367 "AttachStdin": false, 368 "AttachStdout": true, 369 "Cmd": [ 370 "/bin/sh", 371 "-c", 372 "exit 9" 373 ], 374 "Domainname": "", 375 "Entrypoint": null, 376 "Env": [ 377 "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" 378 ], 379 "ExposedPorts": null, 380 "Hostname": "ba033ac44011", 381 "Image": "ubuntu", 382 "Labels": { 383 "com.example.vendor": "Acme", 384 "com.example.license": "GPL", 385 "com.example.version": "1.0" 386 }, 387 "MacAddress": "", 388 "NetworkDisabled": false, 389 "OnBuild": null, 390 "OpenStdin": false, 391 "StdinOnce": false, 392 "Tty": false, 393 "User": "", 394 "Volumes": null, 395 "WorkingDir": "", 396 "StopSignal": "SIGTERM" 397 }, 398 "Created": "2015-01-06T15:47:31.485331387Z", 399 "Driver": "devicemapper", 400 "ExecDriver": "native-0.2", 401 "ExecIDs": null, 402 "HostConfig": { 403 "Binds": null, 404 "BlkioWeight": 0, 405 "CapAdd": null, 406 "CapDrop": null, 407 "ContainerIDFile": "", 408 "CpusetCpus": "", 409 "CpusetMems": "", 410 "CpuShares": 0, 411 "CpuPeriod": 100000, 412 "Devices": [], 413 "Dns": null, 414 "DnsOptions": null, 415 "DnsSearch": null, 416 "ExtraHosts": null, 417 "IpcMode": "", 418 "Links": null, 419 "LxcConf": [], 420 "Memory": 0, 421 "MemorySwap": 0, 422 "MemoryReservation": 0, 423 "KernelMemory": 0, 424 "OomKillDisable": false, 425 "NetworkMode": "bridge", 426 "PidMode": "", 427 "PortBindings": {}, 428 "Privileged": false, 429 "ReadonlyRootfs": false, 430 "PublishAllPorts": false, 431 "RestartPolicy": { 432 "MaximumRetryCount": 2, 433 "Name": "on-failure" 434 }, 435 "LogConfig": { 436 "Config": null, 437 "Type": "json-file" 438 }, 439 "SecurityOpt": null, 440 "VolumesFrom": null, 441 "Ulimits": [{}], 442 "VolumeDriver": "" 443 }, 444 "HostnamePath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/hostname", 445 "HostsPath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/hosts", 446 "LogPath": "/var/lib/docker/containers/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b-json.log", 447 "Id": "ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39", 448 "Image": "04c5d3b7b0656168630d3ba35d8889bd0e9caafcaeb3004d2bfbc47e7c5d35d2", 449 "MountLabel": "", 450 "Name": "/boring_euclid", 451 "NetworkSettings": { 452 "Bridge": "", 453 "SandboxID": "", 454 "HairpinMode": false, 455 "LinkLocalIPv6Address": "", 456 "LinkLocalIPv6PrefixLen": 0, 457 "Ports": null, 458 "SandboxKey": "", 459 "SecondaryIPAddresses": null, 460 "SecondaryIPv6Addresses": null, 461 "EndpointID": "", 462 "Gateway": "", 463 "GlobalIPv6Address": "", 464 "GlobalIPv6PrefixLen": 0, 465 "IPAddress": "", 466 "IPPrefixLen": 0, 467 "IPv6Gateway": "", 468 "MacAddress": "", 469 "Networks": { 470 "bridge": { 471 "EndpointID": "7587b82f0dada3656fda26588aee72630c6fab1536d36e394b2bfbcf898c971d", 472 "Gateway": "172.17.0.1", 473 "IPAddress": "172.17.0.2", 474 "IPPrefixLen": 16, 475 "IPv6Gateway": "", 476 "GlobalIPv6Address": "", 477 "GlobalIPv6PrefixLen": 0, 478 "MacAddress": "02:42:ac:12:00:02" 479 } 480 } 481 }, 482 "Path": "/bin/sh", 483 "ProcessLabel": "", 484 "ResolvConfPath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/resolv.conf", 485 "RestartCount": 1, 486 "State": { 487 "Error": "", 488 "ExitCode": 9, 489 "FinishedAt": "2015-01-06T15:47:32.080254511Z", 490 "OOMKilled": false, 491 "Paused": false, 492 "Pid": 0, 493 "Restarting": false, 494 "Running": true, 495 "StartedAt": "2015-01-06T15:47:32.072697474Z", 496 "Status": "running" 497 }, 498 "Mounts": [ 499 { 500 "Source": "/data", 501 "Destination": "/data", 502 "Mode": "ro,Z", 503 "RW": false 504 } 505 ] 506 } 507 508 **Example request, with size information**: 509 510 GET /containers/4fa6e0f0c678/json?size=1 HTTP/1.1 511 512 **Example response, with size information**: 513 514 HTTP/1.1 200 OK 515 Content-Type: application/json 516 517 { 518 .... 519 "SizeRw": 0, 520 "SizeRootFs": 972, 521 .... 522 } 523 524 **Query parameters**: 525 526 - **size** – 1/True/true or 0/False/false, return container size information. Default is `false`. 527 528 **Status codes**: 529 530 - **200** – no error 531 - **404** – no such container 532 - **500** – server error 533 534 ### List processes running inside a container 535 536 `GET /containers/(id or name)/top` 537 538 List processes running inside the container `id`. On Unix systems this 539 is done by running the `ps` command. This endpoint is not 540 supported on Windows. 541 542 **Example request**: 543 544 GET /containers/4fa6e0f0c678/top HTTP/1.1 545 546 **Example response**: 547 548 HTTP/1.1 200 OK 549 Content-Type: application/json 550 551 { 552 "Titles" : [ 553 "UID", "PID", "PPID", "C", "STIME", "TTY", "TIME", "CMD" 554 ], 555 "Processes" : [ 556 [ 557 "root", "13642", "882", "0", "17:03", "pts/0", "00:00:00", "/bin/bash" 558 ], 559 [ 560 "root", "13735", "13642", "0", "17:06", "pts/0", "00:00:00", "sleep 10" 561 ] 562 ] 563 } 564 565 **Example request**: 566 567 GET /containers/4fa6e0f0c678/top?ps_args=aux HTTP/1.1 568 569 **Example response**: 570 571 HTTP/1.1 200 OK 572 Content-Type: application/json 573 574 { 575 "Titles" : [ 576 "USER","PID","%CPU","%MEM","VSZ","RSS","TTY","STAT","START","TIME","COMMAND" 577 ] 578 "Processes" : [ 579 [ 580 "root","13642","0.0","0.1","18172","3184","pts/0","Ss","17:03","0:00","/bin/bash" 581 ], 582 [ 583 "root","13895","0.0","0.0","4348","692","pts/0","S+","17:15","0:00","sleep 10" 584 ] 585 ], 586 } 587 588 **Query parameters**: 589 590 - **ps_args** – `ps` arguments to use (e.g., `aux`), defaults to `-ef` 591 592 **Status codes**: 593 594 - **200** – no error 595 - **404** – no such container 596 - **500** – server error 597 598 ### Get container logs 599 600 `GET /containers/(id or name)/logs` 601 602 Get `stdout` and `stderr` logs from the container ``id`` 603 604 > **Note**: 605 > This endpoint works only for containers with the `json-file` or `journald` logging drivers. 606 607 **Example request**: 608 609 GET /containers/4fa6e0f0c678/logs?stderr=1&stdout=1×tamps=1&follow=1&tail=10&since=1428990821 HTTP/1.1 610 611 **Example response**: 612 613 HTTP/1.1 101 UPGRADED 614 Content-Type: application/vnd.docker.raw-stream 615 Connection: Upgrade 616 Upgrade: tcp 617 618 {{ STREAM }} 619 620 **Query parameters**: 621 622 - **follow** – 1/True/true or 0/False/false, return stream. Default `false`. 623 - **stdout** – 1/True/true or 0/False/false, show `stdout` log. Default `false`. 624 - **stderr** – 1/True/true or 0/False/false, show `stderr` log. Default `false`. 625 - **since** – UNIX timestamp (integer) to filter logs. Specifying a timestamp 626 will only output log-entries since that timestamp. Default: 0 (unfiltered) 627 - **timestamps** – 1/True/true or 0/False/false, print timestamps for 628 every log line. Default `false`. 629 - **tail** – Output specified number of lines at the end of logs: `all` or `<number>`. Default all. 630 631 **Status codes**: 632 633 - **101** – no error, hints proxy about hijacking 634 - **200** – no error, no upgrade header found 635 - **404** – no such container 636 - **500** – server error 637 638 ### Inspect changes on a container's filesystem 639 640 `GET /containers/(id or name)/changes` 641 642 Inspect changes on container `id`'s filesystem 643 644 **Example request**: 645 646 GET /containers/4fa6e0f0c678/changes HTTP/1.1 647 648 **Example response**: 649 650 HTTP/1.1 200 OK 651 Content-Type: application/json 652 653 [ 654 { 655 "Path": "/dev", 656 "Kind": 0 657 }, 658 { 659 "Path": "/dev/kmsg", 660 "Kind": 1 661 }, 662 { 663 "Path": "/test", 664 "Kind": 1 665 } 666 ] 667 668 Values for `Kind`: 669 670 - `0`: Modify 671 - `1`: Add 672 - `2`: Delete 673 674 **Status codes**: 675 676 - **200** – no error 677 - **404** – no such container 678 - **500** – server error 679 680 ### Export a container 681 682 `GET /containers/(id or name)/export` 683 684 Export the contents of container `id` 685 686 **Example request**: 687 688 GET /containers/4fa6e0f0c678/export HTTP/1.1 689 690 **Example response**: 691 692 HTTP/1.1 200 OK 693 Content-Type: application/octet-stream 694 695 {{ TAR STREAM }} 696 697 **Status codes**: 698 699 - **200** – no error 700 - **404** – no such container 701 - **500** – server error 702 703 ### Get container stats based on resource usage 704 705 `GET /containers/(id or name)/stats` 706 707 This endpoint returns a live stream of a container's resource usage statistics. 708 709 **Example request**: 710 711 GET /containers/redis1/stats HTTP/1.1 712 713 **Example response**: 714 715 HTTP/1.1 200 OK 716 Content-Type: application/json 717 718 { 719 "read" : "2015-01-08T22:57:31.547920715Z", 720 "networks": { 721 "eth0": { 722 "rx_bytes": 5338, 723 "rx_dropped": 0, 724 "rx_errors": 0, 725 "rx_packets": 36, 726 "tx_bytes": 648, 727 "tx_dropped": 0, 728 "tx_errors": 0, 729 "tx_packets": 8 730 }, 731 "eth5": { 732 "rx_bytes": 4641, 733 "rx_dropped": 0, 734 "rx_errors": 0, 735 "rx_packets": 26, 736 "tx_bytes": 690, 737 "tx_dropped": 0, 738 "tx_errors": 0, 739 "tx_packets": 9 740 } 741 }, 742 "memory_stats" : { 743 "stats" : { 744 "total_pgmajfault" : 0, 745 "cache" : 0, 746 "mapped_file" : 0, 747 "total_inactive_file" : 0, 748 "pgpgout" : 414, 749 "rss" : 6537216, 750 "total_mapped_file" : 0, 751 "writeback" : 0, 752 "unevictable" : 0, 753 "pgpgin" : 477, 754 "total_unevictable" : 0, 755 "pgmajfault" : 0, 756 "total_rss" : 6537216, 757 "total_rss_huge" : 6291456, 758 "total_writeback" : 0, 759 "total_inactive_anon" : 0, 760 "rss_huge" : 6291456, 761 "hierarchical_memory_limit" : 67108864, 762 "total_pgfault" : 964, 763 "total_active_file" : 0, 764 "active_anon" : 6537216, 765 "total_active_anon" : 6537216, 766 "total_pgpgout" : 414, 767 "total_cache" : 0, 768 "inactive_anon" : 0, 769 "active_file" : 0, 770 "pgfault" : 964, 771 "inactive_file" : 0, 772 "total_pgpgin" : 477 773 }, 774 "max_usage" : 6651904, 775 "usage" : 6537216, 776 "failcnt" : 0, 777 "limit" : 67108864 778 }, 779 "blkio_stats" : {}, 780 "cpu_stats" : { 781 "cpu_usage" : { 782 "percpu_usage" : [ 783 8646879, 784 24472255, 785 36438778, 786 30657443 787 ], 788 "usage_in_usermode" : 50000000, 789 "total_usage" : 100215355, 790 "usage_in_kernelmode" : 30000000 791 }, 792 "system_cpu_usage" : 739306590000000, 793 "throttling_data" : {"periods":0,"throttled_periods":0,"throttled_time":0} 794 }, 795 "precpu_stats" : { 796 "cpu_usage" : { 797 "percpu_usage" : [ 798 8646879, 799 24350896, 800 36438778, 801 30657443 802 ], 803 "usage_in_usermode" : 50000000, 804 "total_usage" : 100093996, 805 "usage_in_kernelmode" : 30000000 806 }, 807 "system_cpu_usage" : 9492140000000, 808 "throttling_data" : {"periods":0,"throttled_periods":0,"throttled_time":0} 809 } 810 } 811 812 The precpu_stats is the cpu statistic of last read, which is used for calculating the cpu usage percent. It is not the exact copy of the “cpu_stats” field. 813 814 **Query parameters**: 815 816 - **stream** – 1/True/true or 0/False/false, pull stats once then disconnect. Default `true`. 817 818 **Status codes**: 819 820 - **200** – no error 821 - **404** – no such container 822 - **500** – server error 823 824 ### Resize a container TTY 825 826 `POST /containers/(id or name)/resize` 827 828 Resize the TTY for container with `id`. The unit is number of characters. You must restart the container for the resize to take effect. 829 830 **Example request**: 831 832 POST /containers/4fa6e0f0c678/resize?h=40&w=80 HTTP/1.1 833 834 **Example response**: 835 836 HTTP/1.1 200 OK 837 Content-Length: 0 838 Content-Type: text/plain; charset=utf-8 839 840 **Query parameters**: 841 842 - **h** – height of `tty` session 843 - **w** – width 844 845 **Status codes**: 846 847 - **200** – no error 848 - **404** – No such container 849 - **500** – Cannot resize container 850 851 ### Start a container 852 853 `POST /containers/(id or name)/start` 854 855 Start the container `id` 856 857 > **Note**: 858 > For backwards compatibility, this endpoint accepts a `HostConfig` as JSON-encoded request body. 859 > See [create a container](#create-a-container) for details. 860 861 **Example request**: 862 863 POST /containers/e90e34656806/start HTTP/1.1 864 865 **Example response**: 866 867 HTTP/1.1 204 No Content 868 869 **Status codes**: 870 871 - **204** – no error 872 - **304** – container already started 873 - **404** – no such container 874 - **500** – server error 875 876 ### Stop a container 877 878 `POST /containers/(id or name)/stop` 879 880 Stop the container `id` 881 882 **Example request**: 883 884 POST /containers/e90e34656806/stop?t=5 HTTP/1.1 885 886 **Example response**: 887 888 HTTP/1.1 204 No Content 889 890 **Query parameters**: 891 892 - **t** – number of seconds to wait before killing the container 893 894 **Status codes**: 895 896 - **204** – no error 897 - **304** – container already stopped 898 - **404** – no such container 899 - **500** – server error 900 901 ### Restart a container 902 903 `POST /containers/(id or name)/restart` 904 905 Restart the container `id` 906 907 **Example request**: 908 909 POST /containers/e90e34656806/restart?t=5 HTTP/1.1 910 911 **Example response**: 912 913 HTTP/1.1 204 No Content 914 915 **Query parameters**: 916 917 - **t** – number of seconds to wait before killing the container 918 919 **Status codes**: 920 921 - **204** – no error 922 - **404** – no such container 923 - **500** – server error 924 925 ### Kill a container 926 927 `POST /containers/(id or name)/kill` 928 929 Kill the container `id` 930 931 **Example request**: 932 933 POST /containers/e90e34656806/kill HTTP/1.1 934 935 **Example response**: 936 937 HTTP/1.1 204 No Content 938 939 **Query parameters**: 940 941 - **signal** - Signal to send to the container: integer or string like `SIGINT`. 942 When not set, `SIGKILL` is assumed and the call waits for the container to exit. 943 944 **Status codes**: 945 946 - **204** – no error 947 - **404** – no such container 948 - **500** – server error 949 950 ### Rename a container 951 952 `POST /containers/(id or name)/rename` 953 954 Rename the container `id` to a `new_name` 955 956 **Example request**: 957 958 POST /containers/e90e34656806/rename?name=new_name HTTP/1.1 959 960 **Example response**: 961 962 HTTP/1.1 204 No Content 963 964 **Query parameters**: 965 966 - **name** – new name for the container 967 968 **Status codes**: 969 970 - **204** – no error 971 - **404** – no such container 972 - **409** - conflict name already assigned 973 - **500** – server error 974 975 ### Pause a container 976 977 `POST /containers/(id or name)/pause` 978 979 Pause the container `id` 980 981 **Example request**: 982 983 POST /containers/e90e34656806/pause HTTP/1.1 984 985 **Example response**: 986 987 HTTP/1.1 204 No Content 988 989 **Status codes**: 990 991 - **204** – no error 992 - **404** – no such container 993 - **500** – server error 994 995 ### Unpause a container 996 997 `POST /containers/(id or name)/unpause` 998 999 Unpause the container `id` 1000 1001 **Example request**: 1002 1003 POST /containers/e90e34656806/unpause HTTP/1.1 1004 1005 **Example response**: 1006 1007 HTTP/1.1 204 No Content 1008 1009 **Status codes**: 1010 1011 - **204** – no error 1012 - **404** – no such container 1013 - **500** – server error 1014 1015 ### Attach to a container 1016 1017 `POST /containers/(id or name)/attach` 1018 1019 Attach to the container `id` 1020 1021 **Example request**: 1022 1023 POST /containers/16253994b7c4/attach?logs=1&stream=0&stdout=1 HTTP/1.1 1024 1025 **Example response**: 1026 1027 HTTP/1.1 101 UPGRADED 1028 Content-Type: application/vnd.docker.raw-stream 1029 Connection: Upgrade 1030 Upgrade: tcp 1031 1032 {{ STREAM }} 1033 1034 **Query parameters**: 1035 1036 - **logs** – 1/True/true or 0/False/false, return logs. Default `false`. 1037 - **stream** – 1/True/true or 0/False/false, return stream. 1038 Default `false`. 1039 - **stdin** – 1/True/true or 0/False/false, if `stream=true`, attach 1040 to `stdin`. Default `false`. 1041 - **stdout** – 1/True/true or 0/False/false, if `logs=true`, return 1042 `stdout` log, if `stream=true`, attach to `stdout`. Default `false`. 1043 - **stderr** – 1/True/true or 0/False/false, if `logs=true`, return 1044 `stderr` log, if `stream=true`, attach to `stderr`. Default `false`. 1045 1046 **Status codes**: 1047 1048 - **101** – no error, hints proxy about hijacking 1049 - **200** – no error, no upgrade header found 1050 - **400** – bad parameter 1051 - **404** – no such container 1052 - **500** – server error 1053 1054 **Stream details**: 1055 1056 When using the TTY setting is enabled in 1057 [`POST /containers/create` 1058 ](#create-a-container), 1059 the stream is the raw data from the process PTY and client's `stdin`. 1060 When the TTY is disabled, then the stream is multiplexed to separate 1061 `stdout` and `stderr`. 1062 1063 The format is a **Header** and a **Payload** (frame). 1064 1065 **HEADER** 1066 1067 The header contains the information which the stream writes (`stdout` or 1068 `stderr`). It also contains the size of the associated frame encoded in the 1069 last four bytes (`uint32`). 1070 1071 It is encoded on the first eight bytes like this: 1072 1073 header := [8]byte{STREAM_TYPE, 0, 0, 0, SIZE1, SIZE2, SIZE3, SIZE4} 1074 1075 `STREAM_TYPE` can be: 1076 1077 - 0: `stdin` (is written on `stdout`) 1078 - 1: `stdout` 1079 - 2: `stderr` 1080 1081 `SIZE1, SIZE2, SIZE3, SIZE4` are the four bytes of 1082 the `uint32` size encoded as big endian. 1083 1084 **PAYLOAD** 1085 1086 The payload is the raw stream. 1087 1088 **IMPLEMENTATION** 1089 1090 The simplest way to implement the Attach protocol is the following: 1091 1092 1. Read eight bytes. 1093 2. Choose `stdout` or `stderr` depending on the first byte. 1094 3. Extract the frame size from the last four bytes. 1095 4. Read the extracted size and output it on the correct output. 1096 5. Goto 1. 1097 1098 ### Attach to a container (websocket) 1099 1100 `GET /containers/(id or name)/attach/ws` 1101 1102 Attach to the container `id` via websocket 1103 1104 Implements websocket protocol handshake according to [RFC 6455](http://tools.ietf.org/html/rfc6455) 1105 1106 **Example request** 1107 1108 GET /containers/e90e34656806/attach/ws?logs=0&stream=1&stdin=1&stdout=1&stderr=1 HTTP/1.1 1109 1110 **Example response** 1111 1112 {{ STREAM }} 1113 1114 **Query parameters**: 1115 1116 - **logs** – 1/True/true or 0/False/false, return logs. Default `false`. 1117 - **stream** – 1/True/true or 0/False/false, return stream. 1118 Default `false`. 1119 - **stdin** – 1/True/true or 0/False/false, if `stream=true`, attach 1120 to `stdin`. Default `false`. 1121 - **stdout** – 1/True/true or 0/False/false, if `logs=true`, return 1122 `stdout` log, if `stream=true`, attach to `stdout`. Default `false`. 1123 - **stderr** – 1/True/true or 0/False/false, if `logs=true`, return 1124 `stderr` log, if `stream=true`, attach to `stderr`. Default `false`. 1125 1126 **Status codes**: 1127 1128 - **200** – no error 1129 - **400** – bad parameter 1130 - **404** – no such container 1131 - **500** – server error 1132 1133 ### Wait a container 1134 1135 `POST /containers/(id or name)/wait` 1136 1137 Block until container `id` stops, then returns the exit code 1138 1139 **Example request**: 1140 1141 POST /containers/16253994b7c4/wait HTTP/1.1 1142 1143 **Example response**: 1144 1145 HTTP/1.1 200 OK 1146 Content-Type: application/json 1147 1148 {"StatusCode": 0} 1149 1150 **Status codes**: 1151 1152 - **200** – no error 1153 - **404** – no such container 1154 - **500** – server error 1155 1156 ### Remove a container 1157 1158 `DELETE /containers/(id or name)` 1159 1160 Remove the container `id` from the filesystem 1161 1162 **Example request**: 1163 1164 DELETE /containers/16253994b7c4?v=1 HTTP/1.1 1165 1166 **Example response**: 1167 1168 HTTP/1.1 204 No Content 1169 1170 **Query parameters**: 1171 1172 - **v** – 1/True/true or 0/False/false, Remove the volumes 1173 associated to the container. Default `false`. 1174 - **force** - 1/True/true or 0/False/false, Kill then remove the container. 1175 Default `false`. 1176 1177 **Status codes**: 1178 1179 - **204** – no error 1180 - **400** – bad parameter 1181 - **404** – no such container 1182 - **409** – conflict 1183 - **500** – server error 1184 1185 ### Copy files or folders from a container 1186 1187 `POST /containers/(id or name)/copy` 1188 1189 Copy files or folders of container `id` 1190 1191 **Deprecated** in favor of the `archive` endpoint below. 1192 1193 **Example request**: 1194 1195 POST /containers/4fa6e0f0c678/copy HTTP/1.1 1196 Content-Type: application/json 1197 1198 { 1199 "Resource": "test.txt" 1200 } 1201 1202 **Example response**: 1203 1204 HTTP/1.1 200 OK 1205 Content-Type: application/x-tar 1206 1207 {{ TAR STREAM }} 1208 1209 **Status codes**: 1210 1211 - **200** – no error 1212 - **404** – no such container 1213 - **500** – server error 1214 1215 ### Retrieving information about files and folders in a container 1216 1217 `HEAD /containers/(id or name)/archive` 1218 1219 See the description of the `X-Docker-Container-Path-Stat` header in the 1220 following section. 1221 1222 ### Get an archive of a filesystem resource in a container 1223 1224 `GET /containers/(id or name)/archive` 1225 1226 Get a tar archive of a resource in the filesystem of container `id`. 1227 1228 **Query parameters**: 1229 1230 - **path** - resource in the container's filesystem to archive. Required. 1231 1232 If not an absolute path, it is relative to the container's root directory. 1233 The resource specified by **path** must exist. To assert that the resource 1234 is expected to be a directory, **path** should end in `/` or `/.` 1235 (assuming a path separator of `/`). If **path** ends in `/.` then this 1236 indicates that only the contents of the **path** directory should be 1237 copied. A symlink is always resolved to its target. 1238 1239 > **Note**: It is not possible to copy certain system files such as resources 1240 > under `/proc`, `/sys`, `/dev`, and mounts created by the user in the 1241 > container. 1242 1243 **Example request**: 1244 1245 GET /containers/8cce319429b2/archive?path=/root HTTP/1.1 1246 1247 **Example response**: 1248 1249 HTTP/1.1 200 OK 1250 Content-Type: application/x-tar 1251 X-Docker-Container-Path-Stat: eyJuYW1lIjoicm9vdCIsInNpemUiOjQwOTYsIm1vZGUiOjIxNDc0ODQwOTYsIm10aW1lIjoiMjAxNC0wMi0yN1QyMDo1MToyM1oiLCJsaW5rVGFyZ2V0IjoiIn0= 1252 1253 {{ TAR STREAM }} 1254 1255 On success, a response header `X-Docker-Container-Path-Stat` will be set to a 1256 base64-encoded JSON object containing some filesystem header information about 1257 the archived resource. The above example value would decode to the following 1258 JSON object (whitespace added for readability): 1259 1260 ```json 1261 { 1262 "name": "root", 1263 "size": 4096, 1264 "mode": 2147484096, 1265 "mtime": "2014-02-27T20:51:23Z", 1266 "linkTarget": "" 1267 } 1268 ``` 1269 1270 A `HEAD` request can also be made to this endpoint if only this information is 1271 desired. 1272 1273 **Status codes**: 1274 1275 - **200** - success, returns archive of copied resource 1276 - **400** - client error, bad parameter, details in JSON response body, one of: 1277 - must specify path parameter (**path** cannot be empty) 1278 - not a directory (**path** was asserted to be a directory but exists as a 1279 file) 1280 - **404** - client error, resource not found, one of: 1281 – no such container (container `id` does not exist) 1282 - no such file or directory (**path** does not exist) 1283 - **500** - server error 1284 1285 ### Extract an archive of files or folders to a directory in a container 1286 1287 `PUT /containers/(id or name)/archive` 1288 1289 Upload a tar archive to be extracted to a path in the filesystem of container 1290 `id`. 1291 1292 **Query parameters**: 1293 1294 - **path** - path to a directory in the container 1295 to extract the archive's contents into. Required. 1296 1297 If not an absolute path, it is relative to the container's root directory. 1298 The **path** resource must exist. 1299 - **noOverwriteDirNonDir** - If "1", "true", or "True" then it will be an error 1300 if unpacking the given content would cause an existing directory to be 1301 replaced with a non-directory and vice versa. 1302 1303 **Example request**: 1304 1305 PUT /containers/8cce319429b2/archive?path=/vol1 HTTP/1.1 1306 Content-Type: application/x-tar 1307 1308 {{ TAR STREAM }} 1309 1310 **Example response**: 1311 1312 HTTP/1.1 200 OK 1313 1314 **Status codes**: 1315 1316 - **200** – the content was extracted successfully 1317 - **400** - client error, bad parameter, details in JSON response body, one of: 1318 - must specify path parameter (**path** cannot be empty) 1319 - not a directory (**path** should be a directory but exists as a file) 1320 - unable to overwrite existing directory with non-directory 1321 (if **noOverwriteDirNonDir**) 1322 - unable to overwrite existing non-directory with directory 1323 (if **noOverwriteDirNonDir**) 1324 - **403** - client error, permission denied, the volume 1325 or container rootfs is marked as read-only. 1326 - **404** - client error, resource not found, one of: 1327 – no such container (container `id` does not exist) 1328 - no such file or directory (**path** resource does not exist) 1329 - **500** – server error 1330 1331 ## 2.2 Images 1332 1333 ### List Images 1334 1335 `GET /images/json` 1336 1337 **Example request**: 1338 1339 GET /images/json?all=0 HTTP/1.1 1340 1341 **Example response**: 1342 1343 HTTP/1.1 200 OK 1344 Content-Type: application/json 1345 1346 [ 1347 { 1348 "RepoTags": [ 1349 "ubuntu:12.04", 1350 "ubuntu:precise", 1351 "ubuntu:latest" 1352 ], 1353 "Id": "8dbd9e392a964056420e5d58ca5cc376ef18e2de93b5cc90e868a1bbc8318c1c", 1354 "Created": 1365714795, 1355 "Size": 131506275, 1356 "VirtualSize": 131506275, 1357 "Labels": {} 1358 }, 1359 { 1360 "RepoTags": [ 1361 "ubuntu:12.10", 1362 "ubuntu:quantal" 1363 ], 1364 "ParentId": "27cf784147099545", 1365 "Id": "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc", 1366 "Created": 1364102658, 1367 "Size": 24653, 1368 "VirtualSize": 180116135, 1369 "Labels": { 1370 "com.example.version": "v1" 1371 } 1372 } 1373 ] 1374 1375 **Example request, with digest information**: 1376 1377 GET /images/json?digests=1 HTTP/1.1 1378 1379 **Example response, with digest information**: 1380 1381 HTTP/1.1 200 OK 1382 Content-Type: application/json 1383 1384 [ 1385 { 1386 "Created": 1420064636, 1387 "Id": "4986bf8c15363d1c5d15512d5266f8777bfba4974ac56e3270e7760f6f0a8125", 1388 "ParentId": "ea13149945cb6b1e746bf28032f02e9b5a793523481a0a18645fc77ad53c4ea2", 1389 "RepoDigests": [ 1390 "localhost:5000/test/busybox@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf" 1391 ], 1392 "RepoTags": [ 1393 "localhost:5000/test/busybox:latest", 1394 "playdate:latest" 1395 ], 1396 "Size": 0, 1397 "VirtualSize": 2429728, 1398 "Labels": {} 1399 } 1400 ] 1401 1402 The response shows a single image `Id` associated with two repositories 1403 (`RepoTags`): `localhost:5000/test/busybox`: and `playdate`. A caller can use 1404 either of the `RepoTags` values `localhost:5000/test/busybox:latest` or 1405 `playdate:latest` to reference the image. 1406 1407 You can also use `RepoDigests` values to reference an image. In this response, 1408 the array has only one reference and that is to the 1409 `localhost:5000/test/busybox` repository; the `playdate` repository has no 1410 digest. You can reference this digest using the value: 1411 `localhost:5000/test/busybox@sha256:cbbf2f9a99b47fc460d...` 1412 1413 See the `docker run` and `docker build` commands for examples of digest and tag 1414 references on the command line. 1415 1416 **Query parameters**: 1417 1418 - **all** – 1/True/true or 0/False/false, default false 1419 - **filters** – a JSON encoded value of the filters (a map[string][]string) to process on the images list. Available filters: 1420 - `dangling=true` 1421 - `label=key` or `label="key=value"` of an image label 1422 - **filter** - only return images with the specified name 1423 1424 ### Build image from a Dockerfile 1425 1426 `POST /build` 1427 1428 Build an image from a Dockerfile 1429 1430 **Example request**: 1431 1432 POST /build HTTP/1.1 1433 1434 {{ TAR STREAM }} 1435 1436 **Example response**: 1437 1438 HTTP/1.1 200 OK 1439 Content-Type: application/json 1440 1441 {"stream": "Step 1..."} 1442 {"stream": "..."} 1443 {"error": "Error...", "errorDetail": {"code": 123, "message": "Error..."}} 1444 1445 The input stream must be a `tar` archive compressed with one of the 1446 following algorithms: `identity` (no compression), `gzip`, `bzip2`, `xz`. 1447 1448 The archive must include a build instructions file, typically called 1449 `Dockerfile` at the archive's root. The `dockerfile` parameter may be 1450 used to specify a different build instructions file. To do this, its value must be 1451 the path to the alternate build instructions file to use. 1452 1453 The archive may include any number of other files, 1454 which are accessible in the build context (See the [*ADD build 1455 command*](../../reference/builder.md#add)). 1456 1457 The Docker daemon performs a preliminary validation of the `Dockerfile` before 1458 starting the build, and returns an error if the syntax is incorrect. After that, 1459 each instruction is run one-by-one until the ID of the new image is output. 1460 1461 The build is canceled if the client drops the connection by quitting 1462 or being killed. 1463 1464 **Query parameters**: 1465 1466 - **dockerfile** - Path within the build context to the `Dockerfile`. This is 1467 ignored if `remote` is specified and points to an external `Dockerfile`. 1468 - **t** – A name and optional tag to apply to the image in the `name:tag` format. 1469 If you omit the `tag` the default `latest` value is assumed. 1470 You can provide one or more `t` parameters. 1471 - **remote** – A Git repository URI or HTTP/HTTPS context URI. If the 1472 URI points to a single text file, the file's contents are placed into 1473 a file called `Dockerfile` and the image is built from that file. If 1474 the URI points to a tarball, the file is downloaded by the daemon and 1475 the contents therein used as the context for the build. If the URI 1476 points to a tarball and the `dockerfile` parameter is also specified, 1477 there must be a file with the corresponding path inside the tarball. 1478 - **q** – Suppress verbose build output. 1479 - **nocache** – Do not use the cache when building the image. 1480 - **pull** - Attempt to pull the image even if an older image exists locally. 1481 - **rm** - Remove intermediate containers after a successful build (default behavior). 1482 - **forcerm** - Always remove intermediate containers (includes `rm`). 1483 - **memory** - Set memory limit for build. 1484 - **memswap** - Total memory (memory + swap), `-1` to enable unlimited swap. 1485 - **cpushares** - CPU shares (relative weight). 1486 - **cpusetcpus** - CPUs in which to allow execution (e.g., `0-3`, `0,1`). 1487 - **cpuperiod** - The length of a CPU period in microseconds. 1488 - **cpuquota** - Microseconds of CPU time that the container can get in a CPU period. 1489 - **buildargs** – JSON map of string pairs for build-time variables. Users pass 1490 these values at build-time. Docker uses the `buildargs` as the environment 1491 context for command(s) run via the Dockerfile's `RUN` instruction or for 1492 variable expansion in other Dockerfile instructions. This is not meant for 1493 passing secret values. [Read more about the buildargs instruction](../../reference/builder.md#arg) 1494 1495 **Request Headers**: 1496 1497 - **Content-type** – Set to `"application/tar"`. 1498 - **X-Registry-Config** – A base64-url-safe-encoded Registry Auth Config JSON 1499 object with the following structure: 1500 1501 { 1502 "docker.example.com": { 1503 "username": "janedoe", 1504 "password": "hunter2" 1505 }, 1506 "https://index.docker.io/v1/": { 1507 "username": "mobydock", 1508 "password": "conta1n3rize14" 1509 } 1510 } 1511 1512 This object maps the hostname of a registry to an object containing the 1513 "username" and "password" for that registry. Multiple registries may 1514 be specified as the build may be based on an image requiring 1515 authentication to pull from any arbitrary registry. Only the registry 1516 domain name (and port if not the default "443") are required. However 1517 (for legacy reasons) the "official" Docker, Inc. hosted registry must 1518 be specified with both a "https://" prefix and a "/v1/" suffix even 1519 though Docker will prefer to use the v2 registry API. 1520 1521 **Status codes**: 1522 1523 - **200** – no error 1524 - **500** – server error 1525 1526 ### Create an image 1527 1528 `POST /images/create` 1529 1530 Create an image either by pulling it from the registry or by importing it 1531 1532 **Example request**: 1533 1534 POST /images/create?fromImage=busybox&tag=latest HTTP/1.1 1535 1536 **Example response**: 1537 1538 HTTP/1.1 200 OK 1539 Content-Type: application/json 1540 1541 {"status": "Pulling..."} 1542 {"status": "Pulling", "progress": "1 B/ 100 B", "progressDetail": {"current": 1, "total": 100}} 1543 {"error": "Invalid..."} 1544 ... 1545 1546 When using this endpoint to pull an image from the registry, the 1547 `X-Registry-Auth` header can be used to include 1548 a base64-encoded AuthConfig object. 1549 1550 **Query parameters**: 1551 1552 - **fromImage** – Name of the image to pull. The name may include a tag or 1553 digest. This parameter may only be used when pulling an image. 1554 - **fromSrc** – Source to import. The value may be a URL from which the image 1555 can be retrieved or `-` to read the image from the request body. 1556 This parameter may only be used when importing an image. 1557 - **repo** – Repository name given to an image when it is imported. 1558 The repo may include a tag. This parameter may only be used when importing 1559 an image. 1560 - **tag** – Tag or digest. If empty when pulling an image, this causes all tags 1561 for the given image to be pulled. 1562 1563 **Request Headers**: 1564 1565 - **X-Registry-Auth** – base64-encoded AuthConfig object 1566 1567 **Status codes**: 1568 1569 - **200** – no error 1570 - **500** – server error 1571 1572 1573 1574 ### Inspect an image 1575 1576 `GET /images/(name)/json` 1577 1578 Return low-level information on the image `name` 1579 1580 **Example request**: 1581 1582 GET /images/example/json HTTP/1.1 1583 1584 **Example response**: 1585 1586 HTTP/1.1 200 OK 1587 Content-Type: application/json 1588 1589 { 1590 "Id" : "85f05633ddc1c50679be2b16a0479ab6f7637f8884e0cfe0f4d20e1ebb3d6e7c", 1591 "Container" : "cb91e48a60d01f1e27028b4fc6819f4f290b3cf12496c8176ec714d0d390984a", 1592 "Comment" : "", 1593 "Os" : "linux", 1594 "Architecture" : "amd64", 1595 "Parent" : "91e54dfb11794fad694460162bf0cb0a4fa710cfa3f60979c177d920813e267c", 1596 "ContainerConfig" : { 1597 "Tty" : false, 1598 "Hostname" : "e611e15f9c9d", 1599 "Volumes" : null, 1600 "Domainname" : "", 1601 "AttachStdout" : false, 1602 "PublishService" : "", 1603 "AttachStdin" : false, 1604 "OpenStdin" : false, 1605 "StdinOnce" : false, 1606 "NetworkDisabled" : false, 1607 "OnBuild" : [], 1608 "Image" : "91e54dfb11794fad694460162bf0cb0a4fa710cfa3f60979c177d920813e267c", 1609 "User" : "", 1610 "WorkingDir" : "", 1611 "Entrypoint" : null, 1612 "MacAddress" : "", 1613 "AttachStderr" : false, 1614 "Labels" : { 1615 "com.example.license" : "GPL", 1616 "com.example.version" : "1.0", 1617 "com.example.vendor" : "Acme" 1618 }, 1619 "Env" : [ 1620 "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" 1621 ], 1622 "ExposedPorts" : null, 1623 "Cmd" : [ 1624 "/bin/sh", 1625 "-c", 1626 "#(nop) LABEL com.example.vendor=Acme com.example.license=GPL com.example.version=1.0" 1627 ] 1628 }, 1629 "DockerVersion" : "1.9.0-dev", 1630 "VirtualSize" : 188359297, 1631 "Size" : 0, 1632 "Author" : "", 1633 "Created" : "2015-09-10T08:30:53.26995814Z", 1634 "GraphDriver" : { 1635 "Name" : "aufs", 1636 "Data" : null 1637 }, 1638 "RepoDigests" : [ 1639 "localhost:5000/test/busybox/example@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf" 1640 ], 1641 "RepoTags" : [ 1642 "example:1.0", 1643 "example:latest", 1644 "example:stable" 1645 ], 1646 "Config" : { 1647 "Image" : "91e54dfb11794fad694460162bf0cb0a4fa710cfa3f60979c177d920813e267c", 1648 "NetworkDisabled" : false, 1649 "OnBuild" : [], 1650 "StdinOnce" : false, 1651 "PublishService" : "", 1652 "AttachStdin" : false, 1653 "OpenStdin" : false, 1654 "Domainname" : "", 1655 "AttachStdout" : false, 1656 "Tty" : false, 1657 "Hostname" : "e611e15f9c9d", 1658 "Volumes" : null, 1659 "Cmd" : [ 1660 "/bin/bash" 1661 ], 1662 "ExposedPorts" : null, 1663 "Env" : [ 1664 "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" 1665 ], 1666 "Labels" : { 1667 "com.example.vendor" : "Acme", 1668 "com.example.version" : "1.0", 1669 "com.example.license" : "GPL" 1670 }, 1671 "Entrypoint" : null, 1672 "MacAddress" : "", 1673 "AttachStderr" : false, 1674 "WorkingDir" : "", 1675 "User" : "" 1676 } 1677 } 1678 1679 **Status codes**: 1680 1681 - **200** – no error 1682 - **404** – no such image 1683 - **500** – server error 1684 1685 ### Get the history of an image 1686 1687 `GET /images/(name)/history` 1688 1689 Return the history of the image `name` 1690 1691 **Example request**: 1692 1693 GET /images/ubuntu/history HTTP/1.1 1694 1695 **Example response**: 1696 1697 HTTP/1.1 200 OK 1698 Content-Type: application/json 1699 1700 [ 1701 { 1702 "Id": "3db9c44f45209632d6050b35958829c3a2aa256d81b9a7be45b362ff85c54710", 1703 "Created": 1398108230, 1704 "CreatedBy": "/bin/sh -c #(nop) ADD file:eb15dbd63394e063b805a3c32ca7bf0266ef64676d5a6fab4801f2e81e2a5148 in /", 1705 "Tags": [ 1706 "ubuntu:lucid", 1707 "ubuntu:10.04" 1708 ], 1709 "Size": 182964289, 1710 "Comment": "" 1711 }, 1712 { 1713 "Id": "6cfa4d1f33fb861d4d114f43b25abd0ac737509268065cdfd69d544a59c85ab8", 1714 "Created": 1398108222, 1715 "CreatedBy": "/bin/sh -c #(nop) MAINTAINER Tianon Gravi <admwiggin@gmail.com> - mkimage-debootstrap.sh -i iproute,iputils-ping,ubuntu-minimal -t lucid.tar.xz lucid http://archive.ubuntu.com/ubuntu/", 1716 "Tags": null, 1717 "Size": 0, 1718 "Comment": "" 1719 }, 1720 { 1721 "Id": "511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158", 1722 "Created": 1371157430, 1723 "CreatedBy": "", 1724 "Tags": [ 1725 "scratch12:latest", 1726 "scratch:latest" 1727 ], 1728 "Size": 0, 1729 "Comment": "Imported from -" 1730 } 1731 ] 1732 1733 **Status codes**: 1734 1735 - **200** – no error 1736 - **404** – no such image 1737 - **500** – server error 1738 1739 ### Push an image on the registry 1740 1741 `POST /images/(name)/push` 1742 1743 Push the image `name` on the registry 1744 1745 **Example request**: 1746 1747 POST /images/test/push HTTP/1.1 1748 1749 **Example response**: 1750 1751 HTTP/1.1 200 OK 1752 Content-Type: application/json 1753 1754 {"status": "Pushing..."} 1755 {"status": "Pushing", "progress": "1/? (n/a)", "progressDetail": {"current": 1}}} 1756 {"error": "Invalid..."} 1757 ... 1758 1759 If you wish to push an image on to a private registry, that image must already have a tag 1760 into a repository which references that registry `hostname` and `port`. This repository name should 1761 then be used in the URL. This duplicates the command line's flow. 1762 1763 **Example request**: 1764 1765 POST /images/registry.acme.com:5000/test/push HTTP/1.1 1766 1767 1768 **Query parameters**: 1769 1770 - **tag** – The tag to associate with the image on the registry. This is optional. 1771 1772 **Request Headers**: 1773 1774 - **X-Registry-Auth** – base64-encoded AuthConfig object. 1775 1776 **Status codes**: 1777 1778 - **200** – no error 1779 - **404** – no such image 1780 - **500** – server error 1781 1782 ### Tag an image into a repository 1783 1784 `POST /images/(name)/tag` 1785 1786 Tag the image `name` into a repository 1787 1788 **Example request**: 1789 1790 POST /images/test/tag?repo=myrepo&force=0&tag=v42 HTTP/1.1 1791 1792 **Example response**: 1793 1794 HTTP/1.1 201 Created 1795 1796 **Query parameters**: 1797 1798 - **repo** – The repository to tag in 1799 - **force** – 1/True/true or 0/False/false, default false 1800 - **tag** - The new tag name 1801 1802 **Status codes**: 1803 1804 - **201** – no error 1805 - **400** – bad parameter 1806 - **404** – no such image 1807 - **409** – conflict 1808 - **500** – server error 1809 1810 ### Remove an image 1811 1812 `DELETE /images/(name)` 1813 1814 Remove the image `name` from the filesystem 1815 1816 **Example request**: 1817 1818 DELETE /images/test HTTP/1.1 1819 1820 **Example response**: 1821 1822 HTTP/1.1 200 OK 1823 Content-type: application/json 1824 1825 [ 1826 {"Untagged": "3e2f21a89f"}, 1827 {"Deleted": "3e2f21a89f"}, 1828 {"Deleted": "53b4f83ac9"} 1829 ] 1830 1831 **Query parameters**: 1832 1833 - **force** – 1/True/true or 0/False/false, default false 1834 - **noprune** – 1/True/true or 0/False/false, default false 1835 1836 **Status codes**: 1837 1838 - **200** – no error 1839 - **404** – no such image 1840 - **409** – conflict 1841 - **500** – server error 1842 1843 ### Search images 1844 1845 `GET /images/search` 1846 1847 Search for an image on [Docker Hub](https://hub.docker.com). 1848 1849 > **Note**: 1850 > The response keys have changed from API v1.6 to reflect the JSON 1851 > sent by the registry server to the docker daemon's request. 1852 1853 **Example request**: 1854 1855 GET /images/search?term=sshd HTTP/1.1 1856 1857 **Example response**: 1858 1859 HTTP/1.1 200 OK 1860 Content-Type: application/json 1861 1862 [ 1863 { 1864 "description": "", 1865 "is_official": false, 1866 "is_automated": false, 1867 "name": "wma55/u1210sshd", 1868 "star_count": 0 1869 }, 1870 { 1871 "description": "", 1872 "is_official": false, 1873 "is_automated": false, 1874 "name": "jdswinbank/sshd", 1875 "star_count": 0 1876 }, 1877 { 1878 "description": "", 1879 "is_official": false, 1880 "is_automated": false, 1881 "name": "vgauthier/sshd", 1882 "star_count": 0 1883 } 1884 ... 1885 ] 1886 1887 **Query parameters**: 1888 1889 - **term** – term to search 1890 1891 **Status codes**: 1892 1893 - **200** – no error 1894 - **500** – server error 1895 1896 ## 2.3 Misc 1897 1898 ### Check auth configuration 1899 1900 `POST /auth` 1901 1902 Get the default username and email 1903 1904 **Example request**: 1905 1906 POST /auth HTTP/1.1 1907 Content-Type: application/json 1908 1909 { 1910 "username": "hannibal", 1911 "password": "xxxx", 1912 "email": "hannibal@a-team.com", 1913 "serveraddress": "https://index.docker.io/v1/" 1914 } 1915 1916 **Example response**: 1917 1918 HTTP/1.1 200 OK 1919 1920 **Status codes**: 1921 1922 - **200** – no error 1923 - **204** – no error 1924 - **500** – server error 1925 1926 ### Display system-wide information 1927 1928 `GET /info` 1929 1930 Display system-wide information 1931 1932 **Example request**: 1933 1934 GET /info HTTP/1.1 1935 1936 **Example response**: 1937 1938 HTTP/1.1 200 OK 1939 Content-Type: application/json 1940 1941 { 1942 "ClusterStore": "etcd://localhost:2379", 1943 "Containers": 11, 1944 "CpuCfsPeriod": true, 1945 "CpuCfsQuota": true, 1946 "Debug": false, 1947 "DockerRootDir": "/var/lib/docker", 1948 "Driver": "btrfs", 1949 "DriverStatus": [[""]], 1950 "ExecutionDriver": "native-0.1", 1951 "ExperimentalBuild": false, 1952 "HttpProxy": "http://test:test@localhost:8080", 1953 "HttpsProxy": "https://test:test@localhost:8080", 1954 "ID": "7TRN:IPZB:QYBB:VPBQ:UMPP:KARE:6ZNR:XE6T:7EWV:PKF4:ZOJD:TPYS", 1955 "IPv4Forwarding": true, 1956 "Images": 16, 1957 "IndexServerAddress": "https://index.docker.io/v1/", 1958 "InitPath": "/usr/bin/docker", 1959 "InitSha1": "", 1960 "KernelVersion": "3.12.0-1-amd64", 1961 "Labels": [ 1962 "storage=ssd" 1963 ], 1964 "MemTotal": 2099236864, 1965 "MemoryLimit": true, 1966 "NCPU": 1, 1967 "NEventsListener": 0, 1968 "NFd": 11, 1969 "NGoroutines": 21, 1970 "Name": "prod-server-42", 1971 "NoProxy": "9.81.1.160", 1972 "OomKillDisable": true, 1973 "OperatingSystem": "Boot2Docker", 1974 "RegistryConfig": { 1975 "IndexConfigs": { 1976 "docker.io": { 1977 "Mirrors": null, 1978 "Name": "docker.io", 1979 "Official": true, 1980 "Secure": true 1981 } 1982 }, 1983 "InsecureRegistryCIDRs": [ 1984 "127.0.0.0/8" 1985 ] 1986 }, 1987 "ServerVersion": "1.9.0", 1988 "SwapLimit": false, 1989 "SystemTime": "2015-03-10T11:11:23.730591467-07:00" 1990 } 1991 1992 **Status codes**: 1993 1994 - **200** – no error 1995 - **500** – server error 1996 1997 ### Show the docker version information 1998 1999 `GET /version` 2000 2001 Show the docker version information 2002 2003 **Example request**: 2004 2005 GET /version HTTP/1.1 2006 2007 **Example response**: 2008 2009 HTTP/1.1 200 OK 2010 Content-Type: application/json 2011 2012 { 2013 "Version": "1.5.0", 2014 "Os": "linux", 2015 "KernelVersion": "3.18.5-tinycore64", 2016 "GoVersion": "go1.4.1", 2017 "GitCommit": "a8a31ef", 2018 "Arch": "amd64", 2019 "ApiVersion": "1.20", 2020 "Experimental": false 2021 } 2022 2023 **Status codes**: 2024 2025 - **200** – no error 2026 - **500** – server error 2027 2028 ### Ping the docker server 2029 2030 `GET /_ping` 2031 2032 Ping the docker server 2033 2034 **Example request**: 2035 2036 GET /_ping HTTP/1.1 2037 2038 **Example response**: 2039 2040 HTTP/1.1 200 OK 2041 Content-Type: text/plain 2042 2043 OK 2044 2045 **Status codes**: 2046 2047 - **200** - no error 2048 - **500** - server error 2049 2050 ### Create a new image from a container's changes 2051 2052 `POST /commit` 2053 2054 Create a new image from a container's changes 2055 2056 **Example request**: 2057 2058 POST /commit?container=44c004db4b17&comment=message&repo=myrepo HTTP/1.1 2059 Content-Type: application/json 2060 2061 { 2062 "Hostname": "", 2063 "Domainname": "", 2064 "User": "", 2065 "AttachStdin": false, 2066 "AttachStdout": true, 2067 "AttachStderr": true, 2068 "Tty": false, 2069 "OpenStdin": false, 2070 "StdinOnce": false, 2071 "Env": null, 2072 "Cmd": [ 2073 "date" 2074 ], 2075 "Mounts": [ 2076 { 2077 "Source": "/data", 2078 "Destination": "/data", 2079 "Mode": "ro,Z", 2080 "RW": false 2081 } 2082 ], 2083 "Labels": { 2084 "key1": "value1", 2085 "key2": "value2" 2086 }, 2087 "WorkingDir": "", 2088 "NetworkDisabled": false, 2089 "ExposedPorts": { 2090 "22/tcp": {} 2091 } 2092 } 2093 2094 **Example response**: 2095 2096 HTTP/1.1 201 Created 2097 Content-Type: application/json 2098 2099 {"Id": "596069db4bf5"} 2100 2101 **JSON parameters**: 2102 2103 - **config** - the container's configuration 2104 2105 **Query parameters**: 2106 2107 - **container** – source container 2108 - **repo** – repository 2109 - **tag** – tag 2110 - **comment** – commit message 2111 - **author** – author (e.g., "John Hannibal Smith 2112 <[hannibal@a-team.com](mailto:hannibal%40a-team.com)>") 2113 - **pause** – 1/True/true or 0/False/false, whether to pause the container before committing 2114 - **changes** – Dockerfile instructions to apply while committing 2115 2116 **Status codes**: 2117 2118 - **201** – no error 2119 - **404** – no such container 2120 - **500** – server error 2121 2122 ### Monitor Docker's events 2123 2124 `GET /events` 2125 2126 Get container events from docker, in real time via streaming. 2127 2128 Docker containers report the following events: 2129 2130 attach, commit, copy, create, destroy, die, exec_create, exec_start, export, kill, oom, pause, rename, resize, restart, start, stop, top, unpause 2131 2132 Docker images report the following events: 2133 2134 delete, import, pull, push, tag, untag 2135 2136 **Example request**: 2137 2138 GET /events?since=1374067924 2139 2140 **Example response**: 2141 2142 HTTP/1.1 200 OK 2143 Content-Type: application/json 2144 2145 {"status":"pull","id":"busybox:latest","time":1442421700,"timeNano":1442421700598988358} 2146 {"status":"create","id":"5745704abe9caa5","from":"busybox","time":1442421716,"timeNano":1442421716853979870} 2147 {"status":"attach","id":"5745704abe9caa5","from":"busybox","time":1442421716,"timeNano":1442421716894759198} 2148 {"status":"start","id":"5745704abe9caa5","from":"busybox","time":1442421716,"timeNano":1442421716983607193} 2149 2150 **Query parameters**: 2151 2152 - **since** – Timestamp. Show all events created since timestamp and then stream 2153 - **until** – Timestamp. Show events created until given timestamp and stop streaming 2154 - **filters** – A json encoded value of the filters (a map[string][]string) to process on the event list. Available filters: 2155 - `container=<string>`; -- container to filter 2156 - `event=<string>`; -- event to filter 2157 - `image=<string>`; -- image to filter 2158 - `label=<string>`; -- image and container label to filter 2159 2160 **Status codes**: 2161 2162 - **200** – no error 2163 - **500** – server error 2164 2165 ### Get a tarball containing all images in a repository 2166 2167 `GET /images/(name)/get` 2168 2169 Get a tarball containing all images and metadata for the repository specified 2170 by `name`. 2171 2172 If `name` is a specific name and tag (e.g. ubuntu:latest), then only that image 2173 (and its parents) are returned. If `name` is an image ID, similarly only that 2174 image (and its parents) are returned, but with the exclusion of the 2175 'repositories' file in the tarball, as there were no image names referenced. 2176 2177 See the [image tarball format](#image-tarball-format) for more details. 2178 2179 **Example request** 2180 2181 GET /images/ubuntu/get 2182 2183 **Example response**: 2184 2185 HTTP/1.1 200 OK 2186 Content-Type: application/x-tar 2187 2188 Binary data stream 2189 2190 **Status codes**: 2191 2192 - **200** – no error 2193 - **500** – server error 2194 2195 ### Get a tarball containing all images 2196 2197 `GET /images/get` 2198 2199 Get a tarball containing all images and metadata for one or more repositories. 2200 2201 For each value of the `names` parameter: if it is a specific name and tag (e.g. 2202 `ubuntu:latest`), then only that image (and its parents) are returned; if it is 2203 an image ID, similarly only that image (and its parents) are returned and there 2204 would be no names referenced in the 'repositories' file for this image ID. 2205 2206 See the [image tarball format](#image-tarball-format) for more details. 2207 2208 **Example request** 2209 2210 GET /images/get?names=myname%2Fmyapp%3Alatest&names=busybox 2211 2212 **Example response**: 2213 2214 HTTP/1.1 200 OK 2215 Content-Type: application/x-tar 2216 2217 Binary data stream 2218 2219 **Status codes**: 2220 2221 - **200** – no error 2222 - **500** – server error 2223 2224 ### Load a tarball with a set of images and tags into docker 2225 2226 `POST /images/load` 2227 2228 Load a set of images and tags into a Docker repository. 2229 See the [image tarball format](#image-tarball-format) for more details. 2230 2231 **Example request** 2232 2233 POST /images/load 2234 Content-Type: application/x-tar 2235 2236 Tarball in body 2237 2238 **Example response**: 2239 2240 HTTP/1.1 200 OK 2241 2242 **Status codes**: 2243 2244 - **200** – no error 2245 - **500** – server error 2246 2247 ### Image tarball format 2248 2249 An image tarball contains one directory per image layer (named using its long ID), 2250 each containing these files: 2251 2252 - `VERSION`: currently `1.0` - the file format version 2253 - `json`: detailed layer information, similar to `docker inspect layer_id` 2254 - `layer.tar`: A tarfile containing the filesystem changes in this layer 2255 2256 The `layer.tar` file contains `aufs` style `.wh..wh.aufs` files and directories 2257 for storing attribute changes and deletions. 2258 2259 If the tarball defines a repository, the tarball should also include a `repositories` file at 2260 the root that contains a list of repository and tag names mapped to layer IDs. 2261 2262 ``` 2263 {"hello-world": 2264 {"latest": "565a9d68a73f6706862bfe8409a7f659776d4d60a8d096eb4a3cbce6999cc2a1"} 2265 } 2266 ``` 2267 2268 ### Exec Create 2269 2270 `POST /containers/(id or name)/exec` 2271 2272 Sets up an exec instance in a running container `id` 2273 2274 **Example request**: 2275 2276 POST /containers/e90e34656806/exec HTTP/1.1 2277 Content-Type: application/json 2278 2279 { 2280 "AttachStdin": true, 2281 "AttachStdout": true, 2282 "AttachStderr": true, 2283 "Cmd": ["sh"], 2284 "Privileged": true, 2285 "Tty": true, 2286 "User": "123:456" 2287 } 2288 2289 **Example response**: 2290 2291 HTTP/1.1 201 Created 2292 Content-Type: application/json 2293 2294 { 2295 "Id": "f90e34656806", 2296 "Warnings":[] 2297 } 2298 2299 **JSON parameters**: 2300 2301 - **AttachStdin** - Boolean value, attaches to `stdin` of the `exec` command. 2302 - **AttachStdout** - Boolean value, attaches to `stdout` of the `exec` command. 2303 - **AttachStderr** - Boolean value, attaches to `stderr` of the `exec` command. 2304 - **Tty** - Boolean value to allocate a pseudo-TTY. 2305 - **Cmd** - Command to run specified as a string or an array of strings. 2306 - **Privileged** - Boolean value, runs the exec process with extended privileges. 2307 - **User** - A string value specifying the user, and optionally, group to run 2308 the exec process inside the container. Format is one of: `"user"`, 2309 `"user:group"`, `"uid"`, or `"uid:gid"`. 2310 2311 **Status codes**: 2312 2313 - **201** – no error 2314 - **404** – no such container 2315 - **409** - container is paused 2316 - **500** - server error 2317 2318 ### Exec Start 2319 2320 `POST /exec/(id)/start` 2321 2322 Starts a previously set up `exec` instance `id`. If `detach` is true, this API 2323 returns after starting the `exec` command. Otherwise, this API sets up an 2324 interactive session with the `exec` command. 2325 2326 **Example request**: 2327 2328 POST /exec/e90e34656806/start HTTP/1.1 2329 Content-Type: application/json 2330 2331 { 2332 "Detach": false, 2333 "Tty": false 2334 } 2335 2336 **Example response**: 2337 2338 HTTP/1.1 200 OK 2339 Content-Type: application/vnd.docker.raw-stream 2340 2341 {{ STREAM }} 2342 2343 **JSON parameters**: 2344 2345 - **Detach** - Detach from the `exec` command. 2346 - **Tty** - Boolean value to allocate a pseudo-TTY. 2347 2348 **Status codes**: 2349 2350 - **200** – no error 2351 - **404** – no such exec instance 2352 - **409** - container is paused 2353 2354 **Stream details**: 2355 2356 Similar to the stream behavior of `POST /containers/(id or name)/attach` API 2357 2358 ### Exec Resize 2359 2360 `POST /exec/(id)/resize` 2361 2362 Resizes the `tty` session used by the `exec` command `id`. The unit is number of characters. 2363 This API is valid only if `tty` was specified as part of creating and starting the `exec` command. 2364 2365 **Example request**: 2366 2367 POST /exec/e90e34656806/resize?h=40&w=80 HTTP/1.1 2368 Content-Type: text/plain 2369 2370 **Example response**: 2371 2372 HTTP/1.1 201 Created 2373 Content-Type: text/plain 2374 2375 **Query parameters**: 2376 2377 - **h** – height of `tty` session 2378 - **w** – width 2379 2380 **Status codes**: 2381 2382 - **201** – no error 2383 - **404** – no such exec instance 2384 2385 ### Exec Inspect 2386 2387 `GET /exec/(id)/json` 2388 2389 Return low-level information about the `exec` command `id`. 2390 2391 **Example request**: 2392 2393 GET /exec/11fb006128e8ceb3942e7c58d77750f24210e35f879dd204ac975c184b820b39/json HTTP/1.1 2394 2395 **Example response**: 2396 2397 HTTP/1.1 200 OK 2398 Content-Type: plain/text 2399 2400 { 2401 "ID" : "11fb006128e8ceb3942e7c58d77750f24210e35f879dd204ac975c184b820b39", 2402 "Running" : false, 2403 "ExitCode" : 2, 2404 "ProcessConfig" : { 2405 "privileged" : false, 2406 "user" : "", 2407 "tty" : false, 2408 "entrypoint" : "sh", 2409 "arguments" : [ 2410 "-c", 2411 "exit 2" 2412 ] 2413 }, 2414 "OpenStdin" : false, 2415 "OpenStderr" : false, 2416 "OpenStdout" : false, 2417 "Container" : { 2418 "State" : { 2419 "Status" : "running", 2420 "Running" : true, 2421 "Paused" : false, 2422 "Restarting" : false, 2423 "OOMKilled" : false, 2424 "Pid" : 3650, 2425 "ExitCode" : 0, 2426 "Error" : "", 2427 "StartedAt" : "2014-11-17T22:26:03.717657531Z", 2428 "FinishedAt" : "0001-01-01T00:00:00Z" 2429 }, 2430 "ID" : "8f177a186b977fb451136e0fdf182abff5599a08b3c7f6ef0d36a55aaf89634c", 2431 "Created" : "2014-11-17T22:26:03.626304998Z", 2432 "Path" : "date", 2433 "Args" : [], 2434 "Config" : { 2435 "Hostname" : "8f177a186b97", 2436 "Domainname" : "", 2437 "User" : "", 2438 "AttachStdin" : false, 2439 "AttachStdout" : false, 2440 "AttachStderr" : false, 2441 "ExposedPorts" : null, 2442 "Tty" : false, 2443 "OpenStdin" : false, 2444 "StdinOnce" : false, 2445 "Env" : [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ], 2446 "Cmd" : [ 2447 "date" 2448 ], 2449 "Image" : "ubuntu", 2450 "Volumes" : null, 2451 "WorkingDir" : "", 2452 "Entrypoint" : null, 2453 "NetworkDisabled" : false, 2454 "MacAddress" : "", 2455 "OnBuild" : null, 2456 "SecurityOpt" : null 2457 }, 2458 "Image" : "5506de2b643be1e6febbf3b8a240760c6843244c41e12aa2f60ccbb7153d17f5", 2459 "NetworkSettings" : { 2460 "Bridge": "", 2461 "SandboxID": "", 2462 "HairpinMode": false, 2463 "LinkLocalIPv6Address": "", 2464 "LinkLocalIPv6PrefixLen": 0, 2465 "Ports": null, 2466 "SandboxKey": "", 2467 "SecondaryIPAddresses": null, 2468 "SecondaryIPv6Addresses": null, 2469 "EndpointID": "", 2470 "Gateway": "", 2471 "GlobalIPv6Address": "", 2472 "GlobalIPv6PrefixLen": 0, 2473 "IPAddress": "", 2474 "IPPrefixLen": 0, 2475 "IPv6Gateway": "", 2476 "MacAddress": "", 2477 "Networks": { 2478 "bridge": { 2479 "EndpointID": "", 2480 "Gateway": "", 2481 "IPAddress": "", 2482 "IPPrefixLen": 0, 2483 "IPv6Gateway": "", 2484 "GlobalIPv6Address": "", 2485 "GlobalIPv6PrefixLen": 0, 2486 "MacAddress": "" 2487 } 2488 } 2489 }, 2490 "ResolvConfPath" : "/var/lib/docker/containers/8f177a186b977fb451136e0fdf182abff5599a08b3c7f6ef0d36a55aaf89634c/resolv.conf", 2491 "HostnamePath" : "/var/lib/docker/containers/8f177a186b977fb451136e0fdf182abff5599a08b3c7f6ef0d36a55aaf89634c/hostname", 2492 "HostsPath" : "/var/lib/docker/containers/8f177a186b977fb451136e0fdf182abff5599a08b3c7f6ef0d36a55aaf89634c/hosts", 2493 "LogPath": "/var/lib/docker/containers/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b-json.log", 2494 "Name" : "/test", 2495 "Driver" : "aufs", 2496 "ExecDriver" : "native-0.2", 2497 "MountLabel" : "", 2498 "ProcessLabel" : "", 2499 "AppArmorProfile" : "", 2500 "RestartCount" : 0, 2501 "Mounts" : [] 2502 } 2503 } 2504 2505 **Status codes**: 2506 2507 - **200** – no error 2508 - **404** – no such exec instance 2509 - **500** - server error 2510 2511 ## 2.4 Volumes 2512 2513 ### List volumes 2514 2515 `GET /volumes` 2516 2517 **Example request**: 2518 2519 GET /volumes HTTP/1.1 2520 2521 **Example response**: 2522 2523 HTTP/1.1 200 OK 2524 Content-Type: application/json 2525 2526 { 2527 "Volumes": [ 2528 { 2529 "Name": "tardis", 2530 "Driver": "local", 2531 "Mountpoint": "/var/lib/docker/volumes/tardis" 2532 } 2533 ] 2534 } 2535 2536 **Query parameters**: 2537 2538 - **filters** - JSON encoded value of the filters (a `map[string][]string`) to process on the volumes list. There is one available filter: `dangling=true` 2539 2540 **Status codes**: 2541 2542 - **200** - no error 2543 - **500** - server error 2544 2545 ### Create a volume 2546 2547 `POST /volumes/create` 2548 2549 Create a volume 2550 2551 **Example request**: 2552 2553 POST /volumes/create HTTP/1.1 2554 Content-Type: application/json 2555 2556 { 2557 "Name": "tardis" 2558 } 2559 2560 **Example response**: 2561 2562 HTTP/1.1 201 Created 2563 Content-Type: application/json 2564 2565 { 2566 "Name": "tardis", 2567 "Driver": "local", 2568 "Mountpoint": "/var/lib/docker/volumes/tardis" 2569 } 2570 2571 **Status codes**: 2572 2573 - **201** - no error 2574 - **500** - server error 2575 2576 **JSON parameters**: 2577 2578 - **Name** - The new volume's name. If not specified, Docker generates a name. 2579 - **Driver** - Name of the volume driver to use. Defaults to `local` for the name. 2580 - **DriverOpts** - A mapping of driver options and values. These options are 2581 passed directly to the driver and are driver specific. 2582 2583 ### Inspect a volume 2584 2585 `GET /volumes/(name)` 2586 2587 Return low-level information on the volume `name` 2588 2589 **Example request**: 2590 2591 GET /volumes/tardis 2592 2593 **Example response**: 2594 2595 HTTP/1.1 200 OK 2596 Content-Type: application/json 2597 2598 { 2599 "Name": "tardis", 2600 "Driver": "local", 2601 "Mountpoint": "/var/lib/docker/volumes/tardis" 2602 } 2603 2604 **Status codes**: 2605 2606 - **200** - no error 2607 - **404** - no such volume 2608 - **500** - server error 2609 2610 ### Remove a volume 2611 2612 `DELETE /volumes/(name)` 2613 2614 Instruct the driver to remove the volume (`name`). 2615 2616 **Example request**: 2617 2618 DELETE /volumes/tardis HTTP/1.1 2619 2620 **Example response**: 2621 2622 HTTP/1.1 204 No Content 2623 2624 **Status codes**: 2625 2626 - **204** - no error 2627 - **404** - no such volume or volume driver 2628 - **409** - volume is in use and cannot be removed 2629 - **500** - server error 2630 2631 ## 2.5 Networks 2632 2633 ### List networks 2634 2635 `GET /networks` 2636 2637 **Example request**: 2638 2639 GET /networks HTTP/1.1 2640 2641 **Example response**: 2642 2643 ``` 2644 HTTP/1.1 200 OK 2645 Content-Type: application/json 2646 2647 [ 2648 { 2649 "Name": "bridge", 2650 "Id": "f2de39df4171b0dc801e8002d1d999b77256983dfc63041c0f34030aa3977566", 2651 "Scope": "local", 2652 "Driver": "bridge", 2653 "IPAM": { 2654 "Driver": "default", 2655 "Config": [ 2656 { 2657 "Subnet": "172.17.0.0/16" 2658 } 2659 ] 2660 }, 2661 "Containers": { 2662 "39b69226f9d79f5634485fb236a23b2fe4e96a0a94128390a7fbbcc167065867": { 2663 "EndpointID": "ed2419a97c1d9954d05b46e462e7002ea552f216e9b136b80a7db8d98b442eda", 2664 "MacAddress": "02:42:ac:11:00:02", 2665 "IPv4Address": "172.17.0.2/16", 2666 "IPv6Address": "" 2667 } 2668 }, 2669 "Options": { 2670 "com.docker.network.bridge.default_bridge": "true", 2671 "com.docker.network.bridge.enable_icc": "true", 2672 "com.docker.network.bridge.enable_ip_masquerade": "true", 2673 "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0", 2674 "com.docker.network.bridge.name": "docker0", 2675 "com.docker.network.driver.mtu": "1500" 2676 } 2677 }, 2678 { 2679 "Name": "none", 2680 "Id": "e086a3893b05ab69242d3c44e49483a3bbbd3a26b46baa8f61ab797c1088d794", 2681 "Scope": "local", 2682 "Driver": "null", 2683 "IPAM": { 2684 "Driver": "default", 2685 "Config": [] 2686 }, 2687 "Containers": {}, 2688 "Options": {} 2689 }, 2690 { 2691 "Name": "host", 2692 "Id": "13e871235c677f196c4e1ecebb9dc733b9b2d2ab589e30c539efeda84a24215e", 2693 "Scope": "local", 2694 "Driver": "host", 2695 "IPAM": { 2696 "Driver": "default", 2697 "Config": [] 2698 }, 2699 "Containers": {}, 2700 "Options": {} 2701 } 2702 ] 2703 ``` 2704 2705 **Query parameters**: 2706 2707 - **filters** - JSON encoded value of the filters (a `map[string][]string`) to process on the networks list. Available filters: `name=[network-names]` , `id=[network-ids]` 2708 2709 **Status codes**: 2710 2711 - **200** - no error 2712 - **500** - server error 2713 2714 ### Inspect network 2715 2716 `GET /networks/<network-id>` 2717 2718 **Example request**: 2719 2720 GET /networks/f2de39df4171b0dc801e8002d1d999b77256983dfc63041c0f34030aa3977566 HTTP/1.1 2721 2722 **Example response**: 2723 2724 ``` 2725 HTTP/1.1 200 OK 2726 Content-Type: application/json 2727 2728 { 2729 "Name": "bridge", 2730 "Id": "f2de39df4171b0dc801e8002d1d999b77256983dfc63041c0f34030aa3977566", 2731 "Scope": "local", 2732 "Driver": "bridge", 2733 "IPAM": { 2734 "Driver": "default", 2735 "Config": [ 2736 { 2737 "Subnet": "172.17.0.0/16" 2738 } 2739 ] 2740 }, 2741 "Containers": { 2742 "39b69226f9d79f5634485fb236a23b2fe4e96a0a94128390a7fbbcc167065867": { 2743 "EndpointID": "ed2419a97c1d9954d05b46e462e7002ea552f216e9b136b80a7db8d98b442eda", 2744 "MacAddress": "02:42:ac:11:00:02", 2745 "IPv4Address": "172.17.0.2/16", 2746 "IPv6Address": "" 2747 } 2748 }, 2749 "Options": { 2750 "com.docker.network.bridge.default_bridge": "true", 2751 "com.docker.network.bridge.enable_icc": "true", 2752 "com.docker.network.bridge.enable_ip_masquerade": "true", 2753 "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0", 2754 "com.docker.network.bridge.name": "docker0", 2755 "com.docker.network.driver.mtu": "1500" 2756 } 2757 } 2758 ``` 2759 2760 **Status codes**: 2761 2762 - **200** - no error 2763 - **404** - network not found 2764 2765 ### Create a network 2766 2767 `POST /networks/create` 2768 2769 Create a network 2770 2771 **Example request**: 2772 2773 ``` 2774 POST /networks/create HTTP/1.1 2775 Content-Type: application/json 2776 2777 { 2778 "Name":"isolated_nw", 2779 "Driver":"bridge", 2780 "IPAM":{ 2781 "Config":[ 2782 { 2783 "Subnet":"172.20.0.0/16", 2784 "IPRange":"172.20.10.0/24", 2785 "Gateway":"172.20.10.11" 2786 } 2787 ] 2788 } 2789 } 2790 ``` 2791 2792 **Example response**: 2793 2794 ``` 2795 HTTP/1.1 201 Created 2796 Content-Type: application/json 2797 2798 { 2799 "Id": "22be93d5babb089c5aab8dbc369042fad48ff791584ca2da2100db837a1c7c30", 2800 "Warning": "" 2801 } 2802 ``` 2803 2804 **Status codes**: 2805 2806 - **201** - no error 2807 - **404** - plugin not found 2808 - **500** - server error 2809 2810 **JSON parameters**: 2811 2812 - **Name** - The new network's name. this is a mandatory field 2813 - **Driver** - Name of the network driver plugin to use. Defaults to `bridge` driver 2814 - **IPAM** - Optional custom IP scheme for the network 2815 - **Options** - Network specific options to be used by the drivers 2816 - **CheckDuplicate** - Requests daemon to check for networks with same name 2817 2818 ### Connect a container to a network 2819 2820 `POST /networks/(id)/connect` 2821 2822 Connect a container to a network 2823 2824 **Example request**: 2825 2826 ``` 2827 POST /networks/22be93d5babb089c5aab8dbc369042fad48ff791584ca2da2100db837a1c7c30/connect HTTP/1.1 2828 Content-Type: application/json 2829 2830 { 2831 "Container":"3613f73ba0e4" 2832 } 2833 ``` 2834 2835 **Example response**: 2836 2837 HTTP/1.1 200 OK 2838 2839 **Status codes**: 2840 2841 - **200** - no error 2842 - **404** - network or container is not found 2843 - **500** - Internal Server Error 2844 2845 **JSON parameters**: 2846 2847 - **container** - container-id/name to be connected to the network 2848 2849 ### Disconnect a container from a network 2850 2851 `POST /networks/(id)/disconnect` 2852 2853 Disconnect a container from a network 2854 2855 **Example request**: 2856 2857 ``` 2858 POST /networks/22be93d5babb089c5aab8dbc369042fad48ff791584ca2da2100db837a1c7c30/disconnect HTTP/1.1 2859 Content-Type: application/json 2860 2861 { 2862 "Container":"3613f73ba0e4" 2863 } 2864 ``` 2865 2866 **Example response**: 2867 2868 HTTP/1.1 200 OK 2869 2870 **Status codes**: 2871 2872 - **200** - no error 2873 - **404** - network or container not found 2874 - **500** - Internal Server Error 2875 2876 **JSON parameters**: 2877 2878 - **Container** - container-id/name to be disconnected from a network 2879 2880 ### Remove a network 2881 2882 `DELETE /networks/(id)` 2883 2884 Instruct the driver to remove the network (`id`). 2885 2886 **Example request**: 2887 2888 DELETE /networks/22be93d5babb089c5aab8dbc369042fad48ff791584ca2da2100db837a1c7c30 HTTP/1.1 2889 2890 **Example response**: 2891 2892 HTTP/1.1 200 OK 2893 2894 **Status codes**: 2895 2896 - **200** - no error 2897 - **404** - no such network 2898 - **500** - server error 2899 2900 # 3. Going further 2901 2902 ## 3.1 Inside `docker run` 2903 2904 As an example, the `docker run` command line makes the following API calls: 2905 2906 - Create the container 2907 2908 - If the status code is 404, it means the image doesn't exist: 2909 - Try to pull it. 2910 - Then, retry to create the container. 2911 2912 - Start the container. 2913 2914 - If you are not in detached mode: 2915 - Attach to the container, using `logs=1` (to have `stdout` and 2916 `stderr` from the container's start) and `stream=1` 2917 2918 - If in detached mode or only `stdin` is attached, display the container's id. 2919 2920 ## 3.2 Hijacking 2921 2922 In this version of the API, `/attach`, uses hijacking to transport `stdin`, 2923 `stdout`, and `stderr` on the same socket. 2924 2925 To hint potential proxies about connection hijacking, Docker client sends 2926 connection upgrade headers similarly to websocket. 2927 2928 Upgrade: tcp 2929 Connection: Upgrade 2930 2931 When Docker daemon detects the `Upgrade` header, it switches its status code 2932 from **200 OK** to **101 UPGRADED** and resends the same headers. 2933 2934 2935 ## 3.3 CORS Requests 2936 2937 To set cross origin requests to the remote api please give values to 2938 `--api-cors-header` when running Docker in daemon mode. Set * (asterisk) allows all, 2939 default or blank means CORS disabled 2940 2941 $ dockerd -H="192.168.1.9:2375" --api-cors-header="http://foo.bar"