github.com/feiyang21687/docker@v1.5.0/docs/sources/reference/api/docker_remote_api_v1.10.md (about)

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