github.com/vieux/docker@v0.6.3-0.20161004191708-e097c2a938c7/docs/reference/api/docker_remote_api_v1.20.md (about)

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