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