github.com/caseyhadden/docker@v1.6.2/docs/sources/reference/api/docker_remote_api_v1.8.md (about)

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