github.com/nf/docker@v1.8.1/docs/reference/api/docker_remote_api_v1.8.md (about)

     1  <!--[metadata]>
     2  +++
     3  draft = true
     4  title = "Remote API v1.8"
     5  description = "API Documentation for Docker"
     6  keywords = ["API, Docker, rcli, REST,  documentation"]
     7  [menu.main]
     8  parent="smn_remoteapi"
     9  +++
    10  <![end-metadata]-->
    11  
    12  # Docker Remote API v1.8
    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 bind
    18     Docker to another host/port or a Unix socket.
    19   - The API tends to be REST, but for some complex commands, like `attach`
    20     or `pull`, the HTTP connection is hijacked to transport `stdout, stdin`
    21     and `stderr`
    22  
    23  # 2. Endpoints
    24  
    25  ## 2.1 Containers
    26  
    27  ### List containers
    28  
    29  `GET /containers/json`
    30  
    31  List containers
    32  
    33  **Example request**:
    34  
    35          GET /containers/json?all=1&before=8dfafdbc3a40&size=1 HTTP/1.1
    36  
    37  **Example response**:
    38  
    39          HTTP/1.1 200 OK
    40          Content-Type: application/json
    41  
    42          [
    43               {
    44                       "Id": "8dfafdbc3a40",
    45                       "Image": "base:latest",
    46                       "Command": "echo 1",
    47                       "Created": 1367854155,
    48                       "Status": "Exit 0",
    49                       "Ports": [{"PrivatePort": 2222, "PublicPort": 3333, "Type": "tcp"}],
    50                       "SizeRw": 12288,
    51                       "SizeRootFs": 0
    52               },
    53               {
    54                       "Id": "9cd87474be90",
    55                       "Image": "base:latest",
    56                       "Command": "echo 222222",
    57                       "Created": 1367854155,
    58                       "Status": "Exit 0",
    59                       "Ports": [],
    60                       "SizeRw": 12288,
    61                       "SizeRootFs": 0
    62               },
    63               {
    64                       "Id": "3176a2479c92",
    65                       "Image": "base:latest",
    66                       "Command": "echo 3333333333333333",
    67                       "Created": 1367854154,
    68                       "Status": "Exit 0",
    69                       "Ports":[],
    70                       "SizeRw":12288,
    71                       "SizeRootFs":0
    72               },
    73               {
    74                       "Id": "4cb07b47f9fb",
    75                       "Image": "base:latest",
    76                       "Command": "echo 444444444444444444444444444444444",
    77                       "Created": 1367854152,
    78                       "Status": "Exit 0",
    79                       "Ports": [],
    80                       "SizeRw": 12288,
    81                       "SizeRootFs": 0
    82               }
    83          ]
    84  
    85  Query Parameters:
    86  
    87       
    88  
    89  -   **all** – 1/True/true or 0/False/false, Show all containers.
    90      Only running containers are shown by default (i.e., this defaults to false)
    91  -   **limit** – Show `limit` last created containers, include non-running ones.
    92  -   **since** – Show only containers created since Id, include non-running ones.
    93  -   **before** – Show only containers created before Id, include non-running ones.
    94  -   **size** – 1/True/true or 0/False/false, Show the containers sizes
    95  
    96  Status Codes:
    97  
    98  -   **200** – no error
    99  -   **400** – bad parameter
   100  -   **500** – server error
   101  
   102  ### Create a container
   103  
   104  `POST /containers/create`
   105  
   106  Create a container
   107  
   108  **Example request**:
   109  
   110          POST /containers/create HTTP/1.1
   111          Content-Type: application/json
   112  
   113          {
   114               "Hostname":"",
   115               "User":"",
   116               "Memory":0,
   117               "MemorySwap":0,
   118               "CpuShares":0,
   119               "AttachStdin":false,
   120               "AttachStdout":true,
   121               "AttachStderr":true,
   122               "PortSpecs":null,
   123               "Tty":false,
   124               "OpenStdin":false,
   125               "StdinOnce":false,
   126               "Env":null,
   127               "Cmd":[
   128                       "date"
   129               ],
   130               "Dns":null,
   131               "Image":"base",
   132               "Volumes":{
   133                       "/tmp": {}
   134               },
   135               "VolumesFrom":"",
   136               "WorkingDir":"",
   137               "ExposedPorts":{
   138                       "22/tcp": {}
   139               }
   140          }
   141  
   142  **Example response**:
   143  
   144          HTTP/1.1 201 Created
   145          Content-Type: application/json
   146  
   147          {
   148               "Id":"e90e34656806"
   149               "Warnings":[]
   150          }
   151  
   152  Json Parameters:
   153  
   154       
   155  
   156  -   **Hostname** – Container host name
   157  -   **User** – Username or UID
   158  -   **Memory** – Memory Limit in bytes
   159  -   **CpuShares** – CPU shares (relative weight)
   160  -   **AttachStdin** – 1/True/true or 0/False/false, attach to
   161          standard input. Default false
   162  -   **AttachStdout** – 1/True/true or 0/False/false, attach to
   163          standard output. Default false
   164  -   **AttachStderr** – 1/True/true or 0/False/false, attach to
   165          standard error. Default false
   166  -   **Tty** – 1/True/true or 0/False/false, allocate a pseudo-tty.
   167          Default false
   168  -   **OpenStdin** – 1/True/true or 0/False/false, keep stdin open
   169          even if not attached. Default false
   170  
   171  Query Parameters:
   172  
   173       
   174  
   175  -   **name** – Assign the specified name to the container. Mus
   176          match `/?[a-zA-Z0-9_-]+`.
   177  
   178  Status Codes:
   179  
   180  -   **201** – no error
   181  -   **404** – no such container
   182  -   **406** – impossible to attach (container not running)
   183  -   **500** – server error
   184  
   185  ### Inspect a container
   186  
   187  `GET /containers/(id)/json`
   188  
   189  Return low-level information on the container `id`
   190  
   191  **Example request**:
   192  
   193          GET /containers/4fa6e0f0c678/json HTTP/1.1
   194  
   195  **Example response**:
   196  
   197          HTTP/1.1 200 OK
   198          Content-Type: application/json
   199  
   200          {
   201                       "Id": "4fa6e0f0c6786287e131c3852c58a2e01cc697a68231826813597e4994f1d6e2",
   202                       "Created": "2013-05-07T14:51:42.041847+02:00",
   203                       "Path": "date",
   204                       "Args": [],
   205                       "Config": {
   206                               "Hostname": "4fa6e0f0c678",
   207                               "User": "",
   208                               "Memory": 0,
   209                               "MemorySwap": 0,
   210                               "AttachStdin": false,
   211                               "AttachStdout": true,
   212                               "AttachStderr": true,
   213                               "PortSpecs": null,
   214                               "Tty": false,
   215                               "OpenStdin": false,
   216                               "StdinOnce": false,
   217                               "Env": null,
   218                               "Cmd": [
   219                                       "date"
   220                               ],
   221                               "Dns": null,
   222                               "Image": "base",
   223                               "Volumes": {},
   224                               "VolumesFrom": "",
   225                               "WorkingDir": ""
   226                       },
   227                       "State": {
   228                               "Running": false,
   229                               "Pid": 0,
   230                               "ExitCode": 0,
   231                               "StartedAt": "2013-05-07T14:51:42.087658+02:01360",
   232                               "Ghost": false
   233                       },
   234                       "Image": "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc",
   235                       "NetworkSettings": {
   236                               "IpAddress": "",
   237                               "IpPrefixLen": 0,
   238                               "Gateway": "",
   239                               "Bridge": "",
   240                               "PortMapping": null
   241                       },
   242                       "SysInitPath": "/home/kitty/go/src/github.com/docker/docker/bin/docker",
   243                       "ResolvConfPath": "/etc/resolv.conf",
   244                       "Volumes": {},
   245                       "HostConfig": {
   246                           "Binds": null,
   247                           "ContainerIDFile": "",
   248                           "LxcConf": [],
   249                           "Privileged": false,
   250                           "PortBindings": {
   251                              "80/tcp": [
   252                                  {
   253                                      "HostIp": "0.0.0.0",
   254                                      "HostPort": "49153"
   255                                  }
   256                              ]
   257                           },
   258                           "Links": null,
   259                           "PublishAllPorts": false
   260                       }
   261          }
   262  
   263  Status Codes:
   264  
   265  -   **200** – no error
   266  -   **404** – no such container
   267  -   **500** – server error
   268  
   269  ### List processes running inside a container
   270  
   271  `GET /containers/(id)/top`
   272  
   273  List processes running inside the container `id`
   274  
   275  **Example request**:
   276  
   277          GET /containers/4fa6e0f0c678/top HTTP/1.1
   278  
   279  **Example response**:
   280  
   281          HTTP/1.1 200 OK
   282          Content-Type: application/json
   283  
   284          {
   285               "Titles": [
   286                       "USER",
   287                       "PID",
   288                       "%CPU",
   289                       "%MEM",
   290                       "VSZ",
   291                       "RSS",
   292                       "TTY",
   293                       "STAT",
   294                       "START",
   295                       "TIME",
   296                       "COMMAND"
   297                       ],
   298               "Processes": [
   299                       ["root","20147","0.0","0.1","18060","1864","pts/4","S","10:06","0:00","bash"],
   300                       ["root","20271","0.0","0.0","4312","352","pts/4","S+","10:07","0:00","sleep","10"]
   301               ]
   302          }
   303  
   304  Query Parameters:
   305  
   306  -   **ps_args** – ps arguments to use (e.g., aux)
   307  
   308  Status Codes:
   309  
   310  -   **200** – no error
   311  -   **404** – no such container
   312  -   **500** – server error
   313  
   314  ### Inspect changes on a container's filesystem
   315  
   316  `GET /containers/(id)/changes`
   317  
   318  Inspect changes on container `id`'s filesystem
   319  
   320  **Example request**:
   321  
   322          GET /containers/4fa6e0f0c678/changes HTTP/1.1
   323  
   324  **Example response**:
   325  
   326          HTTP/1.1 200 OK
   327          Content-Type: application/json
   328  
   329          [
   330               {
   331                       "Path": "/dev",
   332                       "Kind": 0
   333               },
   334               {
   335                       "Path": "/dev/kmsg",
   336                       "Kind": 1
   337               },
   338               {
   339                       "Path": "/test",
   340                       "Kind": 1
   341               }
   342          ]
   343  
   344  Status Codes:
   345  
   346  -   **200** – no error
   347  -   **404** – no such container
   348  -   **500** – server error
   349  
   350  ### Export a container
   351  
   352  `GET /containers/(id)/export`
   353  
   354  Export the contents of container `id`
   355  
   356  **Example request**:
   357  
   358          GET /containers/4fa6e0f0c678/export HTTP/1.1
   359  
   360  **Example response**:
   361  
   362          HTTP/1.1 200 OK
   363          Content-Type: application/octet-stream
   364  
   365          {{ TAR STREAM }}
   366  
   367  Status Codes:
   368  
   369  -   **200** – no error
   370  -   **404** – no such container
   371  -   **500** – server error
   372  
   373  ### Start a container
   374  
   375  `POST /containers/(id)/start`
   376  
   377  Start the container `id`
   378  
   379  **Example request**:
   380  
   381          POST /containers/(id)/start HTTP/1.1
   382          Content-Type: application/json
   383  
   384          {
   385               "Binds":["/tmp:/tmp"],
   386               "LxcConf":[{"Key":"lxc.utsname","Value":"docker"}],
   387               "PortBindings":{ "22/tcp": [{ "HostPort": "11022" }] },
   388               "PublishAllPorts":false,
   389               "Privileged":false
   390          }
   391  
   392  **Example response**:
   393  
   394          HTTP/1.1 204 No Content
   395          Content-Type: text/plain
   396  
   397  Json Parameters:
   398  
   399       
   400  
   401  -   **Binds** – Create a bind mount to a directory or file with
   402          [host-path]:[container-path]:[rw|ro]. If a directory
   403          "container-path" is missing, then docker creates a new volume.
   404  -   **LxcConf** – Map of custom lxc options
   405  -   **PortBindings** – Expose ports from the container, optionally
   406          publishing them via the HostPort flag
   407  -   **PublishAllPorts** – 1/True/true or 0/False/false, publish all
   408          exposed ports to the host interfaces. Default false
   409  -   **Privileged** – 1/True/true or 0/False/false, give extended
   410          privileges to this container. Default false
   411  
   412  Status Codes:
   413  
   414  -   **204** – no error
   415  -   **404** – no such container
   416  -   **500** – server error
   417  
   418  ### Stop a container
   419  
   420  `POST /containers/(id)/stop`
   421  
   422  Stop the container `id`
   423  
   424  **Example request**:
   425  
   426          POST /containers/e90e34656806/stop?t=5 HTTP/1.1
   427  
   428  **Example response**:
   429  
   430          HTTP/1.1 204 OK
   431  
   432  Query Parameters:
   433  
   434  -   **t** – number of seconds to wait before killing the container
   435  
   436  Status Codes:
   437  
   438  -   **204** – no error
   439  -   **404** – no such container
   440  -   **500** – server error
   441  
   442  ### Restart a container
   443  
   444  `POST /containers/(id)/restart`
   445  
   446  Restart the container `id`
   447  
   448  **Example request**:
   449  
   450          POST /containers/e90e34656806/restart?t=5 HTTP/1.1
   451  
   452  **Example response**:
   453  
   454          HTTP/1.1 204 No Content
   455  
   456  Query Parameters:
   457  
   458  -   **t** – number of seconds to wait before killing the container
   459  
   460  Status Codes:
   461  
   462  -   **204** – no error
   463  -   **404** – no such container
   464  -   **500** – server error
   465  
   466  ### Kill a container
   467  
   468  `POST /containers/(id)/kill`
   469  
   470  Kill the container `id`
   471  
   472  **Example request**:
   473  
   474          POST /containers/e90e34656806/kill HTTP/1.1
   475  
   476  **Example response**:
   477  
   478          HTTP/1.1 204 No Content
   479  
   480  Status Codes:
   481  
   482  -   **204** – no error
   483  -   **404** – no such container
   484  -   **500** – server error
   485  
   486  ### Attach to a container
   487  
   488  `POST /containers/(id)/attach`
   489  
   490  Attach to the container `id`
   491  
   492  **Example request**:
   493  
   494          POST /containers/16253994b7c4/attach?logs=1&stream=0&stdout=1 HTTP/1.1
   495  
   496  **Example response**:
   497  
   498          HTTP/1.1 200 OK
   499          Content-Type: application/vnd.docker.raw-stream
   500  
   501          {{ STREAM }}
   502  
   503  Query Parameters:
   504  
   505  -   **logs** – 1/True/true or 0/False/false, return logs. Defaul
   506          false
   507  -   **stream** – 1/True/true or 0/False/false, return stream.
   508          Default false
   509  -   **stdin** – 1/True/true or 0/False/false, if stream=true, attach
   510          to stdin. Default false
   511  -   **stdout** – 1/True/true or 0/False/false, if logs=true, return
   512          stdout log, if stream=true, attach to stdout. Default false
   513  -   **stderr** – 1/True/true or 0/False/false, if logs=true, return
   514          stderr log, if stream=true, attach to stderr. Default false
   515  
   516  Status Codes:
   517  
   518  -   **200** – no error
   519  -   **400** – bad parameter
   520  -   **404** – no such container
   521  -   **500** – server error
   522  
   523      **Stream details**:
   524  
   525      When using the TTY setting is enabled in
   526      [`POST /containers/create`
   527      ](/reference/api/docker_remote_api_v1.9/#create-a-container "POST /containers/create"),
   528      the stream is the raw data from the process PTY and client's stdin.
   529      When the TTY is disabled, then the stream is multiplexed to separate
   530      stdout and stderr.
   531  
   532      The format is a **Header** and a **Payload** (frame).
   533  
   534      **HEADER**
   535  
   536      The header will contain the information on which stream write the
   537      stream (stdout or stderr). It also contain the size of the
   538      associated frame encoded on the last 4 bytes (uint32).
   539  
   540      It is encoded on the first 8 bytes like this:
   541  
   542          header := [8]byte{STREAM_TYPE, 0, 0, 0, SIZE1, SIZE2, SIZE3, SIZE4}
   543  
   544      `STREAM_TYPE` can be:
   545  
   546  -   0: stdin (will be written on stdout)
   547  -   1: stdout
   548  -   2: stderr
   549  
   550      `SIZE1, SIZE2, SIZE3, SIZE4` are the 4 bytes of
   551      the uint32 size encoded as big endian.
   552  
   553      **PAYLOAD**
   554  
   555      The payload is the raw stream.
   556  
   557      **IMPLEMENTATION**
   558  
   559      The simplest way to implement the Attach protocol is the following:
   560  
   561      1.  Read 8 bytes
   562      2.  chose stdout or stderr depending on the first byte
   563      3.  Extract the frame size from the last 4 bytes
   564      4.  Read the extracted size and output it on the correct output
   565      5.  Goto 1)
   566  
   567  ### Attach to a container (websocket)
   568  
   569  `GET /containers/(id)/attach/ws`
   570  
   571  Attach to the container `id` via websocket
   572  
   573  Implements websocket protocol handshake according to [RFC 6455](http://tools.ietf.org/html/rfc6455)
   574  
   575  **Example request**
   576  
   577          GET /containers/e90e34656806/attach/ws?logs=0&stream=1&stdin=1&stdout=1&stderr=1 HTTP/1.1
   578  
   579  **Example response**
   580  
   581          {{ STREAM }}
   582  
   583  Query Parameters:
   584  
   585  -   **logs** – 1/True/true or 0/False/false, return logs. Default false
   586  -   **stream** – 1/True/true or 0/False/false, return stream.
   587          Default false
   588  -   **stdin** – 1/True/true or 0/False/false, if stream=true, attach
   589          to stdin. Default false
   590  -   **stdout** – 1/True/true or 0/False/false, if logs=true, return
   591          stdout log, if stream=true, attach to stdout. Default false
   592  -   **stderr** – 1/True/true or 0/False/false, if logs=true, return
   593          stderr log, if stream=true, attach to stderr. Default false
   594  
   595  Status Codes:
   596  
   597  -   **200** – no error
   598  -   **400** – bad parameter
   599  -   **404** – no such container
   600  -   **500** – server error
   601  
   602  ### Wait a container
   603  
   604  `POST /containers/(id)/wait`
   605  
   606  Block until container `id` stops, then returns the exit code
   607  
   608  **Example request**:
   609  
   610          POST /containers/16253994b7c4/wait HTTP/1.1
   611  
   612  **Example response**:
   613  
   614          HTTP/1.1 200 OK
   615          Content-Type: application/json
   616  
   617          {"StatusCode": 0}
   618  
   619  Status Codes:
   620  
   621  -   **200** – no error
   622  -   **404** – no such container
   623  -   **500** – server error
   624  
   625  ### Remove a container
   626  
   627  `DELETE /containers/(id)`
   628  
   629  Remove the container `id` from the filesystem
   630  
   631  **Example request**:
   632  
   633          DELETE /containers/16253994b7c4?v=1 HTTP/1.1
   634  
   635  **Example response**:
   636  
   637          HTTP/1.1 204 No Content
   638  
   639  Query Parameters:
   640  
   641  -   **v** – 1/True/true or 0/False/false, Remove the volumes
   642          associated to the container. Default false
   643  
   644  Status Codes:
   645  
   646  -   **204** – no error
   647  -   **400** – bad parameter
   648  -   **404** – no such container
   649  -   **500** – server error
   650  
   651  ### Copy files or folders from a container
   652  
   653  `POST /containers/(id)/copy`
   654  
   655  Copy files or folders of container `id`
   656  
   657  **Example request**:
   658  
   659          POST /containers/4fa6e0f0c678/copy HTTP/1.1
   660          Content-Type: application/json
   661  
   662          {
   663               "Resource": "test.txt"
   664          }
   665  
   666  **Example response**:
   667  
   668          HTTP/1.1 200 OK
   669          Content-Type: application/octet-stream
   670  
   671          {{ TAR STREAM }}
   672  
   673  Status Codes:
   674  
   675  -   **200** – no error
   676  -   **404** – no such container
   677  -   **500** – server error
   678  
   679  ## 2.2 Images
   680  
   681  ### List Images
   682  
   683  `GET /images/json`
   684  
   685  **Example request**:
   686  
   687          GET /images/json?all=0 HTTP/1.1
   688  
   689  **Example response**:
   690  
   691          HTTP/1.1 200 OK
   692          Content-Type: application/json
   693  
   694          [
   695            {
   696               "RepoTags": [
   697                 "ubuntu:12.04",
   698                 "ubuntu:precise",
   699                 "ubuntu:latest"
   700               ],
   701               "Id": "8dbd9e392a964056420e5d58ca5cc376ef18e2de93b5cc90e868a1bbc8318c1c",
   702               "Created": 1365714795,
   703               "Size": 131506275,
   704               "VirtualSize": 131506275
   705            },
   706            {
   707               "RepoTags": [
   708                 "ubuntu:12.10",
   709                 "ubuntu:quantal"
   710               ],
   711               "ParentId": "27cf784147099545",
   712               "Id": "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc",
   713               "Created": 1364102658,
   714               "Size": 24653,
   715               "VirtualSize": 180116135
   716            }
   717          ]
   718  
   719  ### Create an image
   720  
   721  `POST /images/create`
   722  
   723  Create an image, either by pull it from the registry or by importing i
   724  
   725  **Example request**:
   726  
   727          POST /images/create?fromImage=base HTTP/1.1
   728  
   729  **Example response**:
   730  
   731          HTTP/1.1 200 OK
   732          Content-Type: application/json
   733  
   734          {"status": "Pulling..."}
   735          {"status": "Pulling", "progress": "1 B/ 100 B", "progressDetail": {"current": 1, "total": 100}}
   736          {"error": "Invalid..."}
   737          ...
   738  
   739      When using this endpoint to pull an image from the registry, the
   740      `X-Registry-Auth` header can be used to include
   741      a base64-encoded AuthConfig object.
   742  
   743  Query Parameters:
   744  
   745  -   **fromImage** – name of the image to pull
   746  -   **fromSrc** – source to import, - means stdin
   747  -   **repo** – repository
   748  -   **tag** – tag
   749  -   **registry** – the registry to pull from
   750  
   751  Request Headers:
   752  
   753  -   **X-Registry-Auth** – base64-encoded AuthConfig object
   754  
   755  Status Codes:
   756  
   757  -   **200** – no error
   758  -   **500** – server error
   759  
   760  ### Insert a file in an image
   761  
   762  `POST /images/(name)/insert`
   763  
   764  Insert a file from `url` in the image `name` at `path`
   765  
   766  **Example request**:
   767  
   768          POST /images/test/insert?path=/usr&url=myurl HTTP/1.1
   769  
   770  **Example response**:
   771  
   772          HTTP/1.1 200 OK
   773          Content-Type: application/json
   774  
   775          {"status":"Inserting..."}
   776          {"status":"Inserting", "progress":"1/? (n/a)", "progressDetail":{"current":1}}
   777          {"error":"Invalid..."}
   778          ...
   779  
   780  Query Parameters:
   781  
   782  -	**url** – The url from where the file is taken
   783  -	**path** – The path where the file is stored
   784  
   785  Status Codes:
   786  
   787  -   **200** – no error
   788  -   **500** – server error
   789  
   790  ### Inspect an image
   791  
   792  `GET /images/(name)/json`
   793  
   794  Return low-level information on the image `name`
   795  
   796  **Example request**:
   797  
   798          GET /images/base/json HTTP/1.1
   799  
   800  **Example response**:
   801  
   802          HTTP/1.1 200 OK
   803          Content-Type: application/json
   804  
   805          {
   806               "id":"b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc",
   807               "parent":"27cf784147099545",
   808               "created":"2013-03-23T22:24:18.818426-07:00",
   809               "container":"3d67245a8d72ecf13f33dffac9f79dcdf70f75acb84d308770391510e0c23ad0",
   810               "container_config":
   811                       {
   812                               "Hostname":"",
   813                               "User":"",
   814                               "Memory":0,
   815                               "MemorySwap":0,
   816                               "AttachStdin":false,
   817                               "AttachStdout":false,
   818                               "AttachStderr":false,
   819                               "PortSpecs":null,
   820                               "Tty":true,
   821                               "OpenStdin":true,
   822                               "StdinOnce":false,
   823                               "Env":null,
   824                               "Cmd": ["/bin/bash"],
   825                               "Dns":null,
   826                               "Image":"base",
   827                               "Volumes":null,
   828                               "VolumesFrom":"",
   829                               "WorkingDir":""
   830                       },
   831               "Size": 6824592
   832          }
   833  
   834  Status Codes:
   835  
   836  -   **200** – no error
   837  -   **404** – no such image
   838  -   **500** – server error
   839  
   840  ### Get the history of an image
   841  
   842  `GET /images/(name)/history`
   843  
   844  Return the history of the image `name`
   845  
   846  **Example request**:
   847  
   848          GET /images/base/history HTTP/1.1
   849  
   850  **Example response**:
   851  
   852          HTTP/1.1 200 OK
   853          Content-Type: application/json
   854  
   855          [
   856               {
   857                       "Id": "b750fe79269d",
   858                       "Created": 1364102658,
   859                       "CreatedBy": "/bin/bash"
   860               },
   861               {
   862                       "Id": "27cf78414709",
   863                       "Created": 1364068391,
   864                       "CreatedBy": ""
   865               }
   866          ]
   867  
   868  Status Codes:
   869  
   870  -   **200** – no error
   871  -   **404** – no such image
   872  -   **500** – server error
   873  
   874  ### Push an image on the registry
   875  
   876  `POST /images/(name)/push`
   877  
   878  Push the image `name` on the registry
   879  
   880  **Example request**:
   881  
   882          POST /images/test/push HTTP/1.1
   883  
   884  **Example response**:
   885  
   886          HTTP/1.1 200 OK
   887          Content-Type: application/json
   888  
   889          {"status": "Pushing..."}
   890          {"status": "Pushing", "progress": "1/? (n/a)", "progressDetail": {"current": 1}}}
   891          {"error": "Invalid..."}
   892          ...
   893  
   894      Request Headers:
   895  
   896       
   897  
   898  -   **X-Registry-Auth** – include a base64-encoded AuthConfig
   899          object.
   900  
   901  Status Codes:
   902  
   903  -   **200** – no error
   904  -   **404** – no such image
   905  -   **500** – server error
   906  
   907  ### Tag an image into a repository
   908  
   909  `POST /images/(name)/tag`
   910  
   911  Tag the image `name` into a repository
   912  
   913  **Example request**:
   914  
   915          POST /images/test/tag?repo=myrepo&force=0&tag=v42 HTTP/1.1
   916  
   917  **Example response**:
   918  
   919          HTTP/1.1 201 OK
   920  
   921  Query Parameters:
   922  
   923  -   **repo** – The repository to tag in
   924  -   **force** – 1/True/true or 0/False/false, default false
   925  -   **tag** - The new tag name
   926  
   927  Status Codes:
   928  
   929  -   **201** – no error
   930  -   **400** – bad parameter
   931  -   **404** – no such image
   932  -   **409** – conflict
   933  -   **500** – server error
   934  
   935  ### Remove an image
   936  
   937  `DELETE /images/(name)`
   938  
   939  Remove the image `name` from the filesystem
   940  
   941  **Example request**:
   942  
   943          DELETE /images/test HTTP/1.1
   944  
   945  **Example response**:
   946  
   947          HTTP/1.1 200 OK
   948          Content-type: application/json
   949  
   950          [
   951           {"Untagged": "3e2f21a89f"},
   952           {"Deleted": "3e2f21a89f"},
   953           {"Deleted": "53b4f83ac9"}
   954          ]
   955  
   956  Status Codes:
   957  
   958  -   **200** – no error
   959  -   **404** – no such image
   960  -   **409** – conflict
   961  -   **500** – server error
   962  
   963  ### Search images
   964  
   965  `GET /images/search`
   966  
   967  Search for an image on [Docker Hub](https://hub.docker.com).
   968  
   969  > **Note**:
   970  > The response keys have changed from API v1.6 to reflect the JSON
   971  > sent by the registry server to the docker daemon's request.
   972  
   973  **Example request**:
   974  
   975          GET /images/search?term=sshd HTTP/1.1
   976  
   977  **Example response**:
   978  
   979          HTTP/1.1 200 OK
   980          Content-Type: application/json
   981  
   982          [
   983                  {
   984                      "description": "",
   985                      "is_official": false,
   986                      "is_trusted": false,
   987                      "name": "wma55/u1210sshd",
   988                      "star_count": 0
   989                  },
   990                  {
   991                      "description": "",
   992                      "is_official": false,
   993                      "is_trusted": false,
   994                      "name": "jdswinbank/sshd",
   995                      "star_count": 0
   996                  },
   997                  {
   998                      "description": "",
   999                      "is_official": false,
  1000                      "is_trusted": false,
  1001                      "name": "vgauthier/sshd",
  1002                      "star_count": 0
  1003                  }
  1004          ...
  1005          ]
  1006  
  1007  Query Parameters:
  1008  
  1009  -   **term** – term to search
  1010  
  1011  Status Codes:
  1012  
  1013  -   **200** – no error
  1014  -   **500** – server error
  1015  
  1016  ## 2.3 Misc
  1017  
  1018  ### Build an image from Dockerfile via stdin
  1019  
  1020  `POST /build`
  1021  
  1022  Build an image from Dockerfile via stdin
  1023  
  1024  **Example request**:
  1025  
  1026          POST /build HTTP/1.1
  1027  
  1028          {{ TAR STREAM }}
  1029  
  1030  **Example response**:
  1031  
  1032          HTTP/1.1 200 OK
  1033          Content-Type: application/json
  1034  
  1035          {"stream": "Step 1..."}
  1036          {"stream": "..."}
  1037          {"error": "Error...", "errorDetail": {"code": 123, "message": "Error..."}}
  1038  
  1039      The stream must be a tar archive compressed with one of the
  1040      following algorithms: identity (no compression), gzip, bzip2, xz.
  1041  
  1042      The archive must include a file called `Dockerfile`
  1043      at its root. It may include any number of other files,
  1044      which will be accessible in the build context (See the [*ADD build
  1045      command*](/reference/builder/#dockerbuilder)).
  1046  
  1047  Query Parameters:
  1048  
  1049  -   **t** – repository name (and optionally a tag) to be applied to
  1050      the resulting image in case of success
  1051  -   **remote** – build source URI (git or HTTPS/HTTP)
  1052  -   **q** – suppress verbose build output
  1053  -   **nocache** – do not use the cache when building the image
  1054  
  1055      Request Headers:
  1056  
  1057       
  1058  
  1059  -   **Content-type** – should be set to
  1060          `"application/tar"`.
  1061  -   **X-Registry-Auth** – base64-encoded AuthConfig objec
  1062  
  1063  Status Codes:
  1064  
  1065  -   **200** – no error
  1066  -   **500** – server error
  1067  
  1068  ### Check auth configuration
  1069  
  1070  `POST /auth`
  1071  
  1072  Get the default username and email
  1073  
  1074  **Example request**:
  1075  
  1076          POST /auth HTTP/1.1
  1077          Content-Type: application/json
  1078  
  1079          {
  1080               "username":" hannibal",
  1081               "password: "xxxx",
  1082               "email": "hannibal@a-team.com",
  1083               "serveraddress": "https://index.docker.io/v1/"
  1084          }
  1085  
  1086  **Example response**:
  1087  
  1088          HTTP/1.1 200 OK
  1089          Content-Type: text/plain
  1090  
  1091  Status Codes:
  1092  
  1093  -   **200** – no error
  1094  -   **204** – no error
  1095  -   **500** – server error
  1096  
  1097  ### Display system-wide information
  1098  
  1099  `GET /info`
  1100  
  1101  Display system-wide information
  1102  
  1103  **Example request**:
  1104  
  1105          GET /info HTTP/1.1
  1106  
  1107  **Example response**:
  1108  
  1109          HTTP/1.1 200 OK
  1110          Content-Type: application/json
  1111  
  1112          {
  1113               "Containers":11,
  1114               "Images":16,
  1115               "Debug":false,
  1116               "NFd": 11,
  1117               "NGoroutines":21,
  1118               "MemoryLimit":true,
  1119               "SwapLimit":false,
  1120               "IPv4Forwarding":true
  1121          }
  1122  
  1123  Status Codes:
  1124  
  1125  -   **200** – no error
  1126  -   **500** – server error
  1127  
  1128  ### Show the docker version information
  1129  
  1130  `GET /version`
  1131  
  1132  Show the docker version information
  1133  
  1134  **Example request**:
  1135  
  1136          GET /version HTTP/1.1
  1137  
  1138  **Example response**:
  1139  
  1140          HTTP/1.1 200 OK
  1141          Content-Type: application/json
  1142  
  1143          {
  1144               "Version":"0.2.2",
  1145               "GitCommit":"5a2a5cc+CHANGES",
  1146               "GoVersion":"go1.0.3"
  1147          }
  1148  
  1149  Status Codes:
  1150  
  1151  -   **200** – no error
  1152  -   **500** – server error
  1153  
  1154  ### Create a new image from a container's changes
  1155  
  1156  `POST /commit`
  1157  
  1158  Create a new image from a container's changes
  1159  
  1160  **Example request**:
  1161  
  1162          POST /commit?container=44c004db4b17&m=message&repo=myrepo HTTP/1.1
  1163  
  1164  **Example response**:
  1165  
  1166          HTTP/1.1 201 OK
  1167              Content-Type: application/vnd.docker.raw-stream
  1168  
  1169          {"Id": "596069db4bf5"}
  1170  
  1171  Query Parameters:
  1172  
  1173  -   **container** – source container
  1174  -   **repo** – repository
  1175  -   **tag** – tag
  1176  -   **m** – commit message
  1177  -   **author** – author (e.g., "John Hannibal Smith
  1178          <[hannibal@a-team.com](mailto:hannibal%40a-team.com)>")
  1179  -   **run** – config automatically applied when the image is run.
  1180          (ex: {"Cmd": ["cat", "/world"], "PortSpecs":["22"]})
  1181  
  1182  Status Codes:
  1183  
  1184  -   **201** – no error
  1185  -   **404** – no such container
  1186  -   **500** – server error
  1187  
  1188  ### Monitor Docker's events
  1189  
  1190  `GET /events`
  1191  
  1192  Get events from docker, either in real time via streaming,
  1193  or via polling (using since).
  1194  
  1195  Docker containers will report the following events:
  1196  
  1197      create, destroy, die, export, kill, pause, restart, start, stop, unpause
  1198  
  1199  and Docker images will report:
  1200  
  1201      untag, delete
  1202  
  1203  **Example request**:
  1204  
  1205          GET /events?since=1374067924
  1206  
  1207  **Example response**:
  1208  
  1209          HTTP/1.1 200 OK
  1210          Content-Type: application/json
  1211  
  1212          {"status": "create", "id": "dfdf82bd3881","from": "base:latest", "time":1374067924}
  1213          {"status": "start", "id": "dfdf82bd3881","from": "base:latest", "time":1374067924}
  1214          {"status": "stop", "id": "dfdf82bd3881","from": "base:latest", "time":1374067966}
  1215          {"status": "destroy", "id": "dfdf82bd3881","from": "base:latest", "time":1374067970}
  1216  
  1217  Query Parameters:
  1218  
  1219  -   **since** – timestamp used for polling
  1220  
  1221  Status Codes:
  1222  
  1223  -   **200** – no error
  1224  -   **500** – server error
  1225  
  1226  ### Get a tarball containing all images and tags in a repository
  1227  
  1228  `GET /images/(name)/get`
  1229  
  1230  Get a tarball containing all images and metadata for the repository
  1231  specified by `name`.
  1232  See the [image tarball format](#image-tarball-format) for more details.
  1233  
  1234  **Example request**
  1235  
  1236          GET /images/ubuntu/get
  1237  
  1238  **Example response**:
  1239  
  1240          HTTP/1.1 200 OK
  1241          Content-Type: application/x-tar
  1242  
  1243          Binary data stream
  1244  
  1245  Status Codes:
  1246  
  1247  -   **200** – no error
  1248  -   **500** – server error
  1249  
  1250  ### Load a tarball with a set of images and tags into docker
  1251  
  1252  `POST /images/load`
  1253  
  1254  Load a set of images and tags into the docker repository.
  1255  
  1256  See the [image tarball format](#image-tarball-format) for more details.
  1257  
  1258  **Example request**
  1259  
  1260          POST /images/load
  1261  
  1262          Tarball in body
  1263  
  1264  **Example response**:
  1265  
  1266          HTTP/1.1 200 OK
  1267  
  1268  Status Codes:
  1269  
  1270  -   **200** – no error
  1271  -   **500** – server error
  1272  
  1273  ### Image tarball format
  1274  
  1275  An image tarball contains one directory per image layer (named using its long ID),
  1276  each containing three files:
  1277  
  1278  1. `VERSION`: currently `1.0` - the file format version
  1279  2. `json`: detailed layer information, similar to `docker inspect layer_id`
  1280  3. `layer.tar`: A tarfile containing the filesystem changes in this layer
  1281  
  1282  The `layer.tar` file will contain `aufs` style `.wh..wh.aufs` files and directories
  1283  for storing attribute changes and deletions.
  1284  
  1285  If the tarball defines a repository, there will also be a `repositories` file at
  1286  the root that contains a list of repository and tag names mapped to layer IDs.
  1287  
  1288  ```
  1289  {"hello-world":
  1290      {"latest": "565a9d68a73f6706862bfe8409a7f659776d4d60a8d096eb4a3cbce6999cc2a1"}
  1291  }
  1292  ```
  1293  
  1294  # 3. Going further
  1295  
  1296  ## 3.1 Inside `docker run`
  1297  
  1298  Here are the steps of `docker run`:
  1299  
  1300   - Create the container
  1301  
  1302   - If the status code is 404, it means the image doesn't exist:
  1303          - Try to pull it
  1304          - Then retry to create the container
  1305  
  1306   - Start the container
  1307  
  1308   - If you are not in detached mode:
  1309          - Attach to the container, using logs=1 (to have stdout and
  1310              stderr from the container's start) and stream=1
  1311  
  1312   - If in detached mode or only stdin is attached:
  1313          - Display the container's id
  1314  
  1315  ## 3.2 Hijacking
  1316  
  1317  In this version of the API, /attach, uses hijacking to transport stdin,
  1318  stdout and stderr on the same socket. This might change in the future.
  1319  
  1320  ## 3.3 CORS Requests
  1321  
  1322  To enable cross origin requests to the remote api add the flag
  1323  "--api-enable-cors" when running docker in daemon mode.
  1324  
  1325      $ docker -d -H="192.168.1.9:2375" --api-enable-cors