github.com/pritambaral/docker@v1.4.2-0.20150120174542-b2fe1b3dd952/docs/sources/reference/api/docker_remote_api_v1.6.md (about)

     1  page_title: Remote API v1.6
     2  page_description: API Documentation for Docker
     3  page_keywords: API, Docker, rcli, REST, documentation
     4  
     5  # Docker Remote API v1.6
     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               "AttachStdin":false,
   112               "AttachStdout":true,
   113               "AttachStderr":true,
   114               "ExposedPorts":{},
   115               "Tty":false,
   116               "OpenStdin":false,
   117               "StdinOnce":false,
   118               "Env":null,
   119               "Cmd":[
   120                       "date"
   121               ],
   122               "Dns":null,
   123               "Image":"base",
   124               "Volumes":{},
   125               "VolumesFrom":"",
   126               "WorkingDir":""
   127          }
   128  
   129  **Example response**:
   130  
   131          HTTP/1.1 201 Created
   132          Content-Type: application/json
   133  
   134          {
   135               "Id":"e90e34656806"
   136               "Warnings":[]
   137          }
   138  
   139  Json Parameters:
   140  
   141  -   **config** – the container's configuration
   142  
   143  Query Parameters:
   144  
   145       
   146  
   147  -   **name** – container name to use
   148  
   149  Status Codes:
   150  
   151  -   **201** – no error
   152  -   **404** – no such container
   153  -   **406** – impossible to attach (container not running)
   154  -   **500** – server error
   155  
   156      **More Complex Example request, in 2 steps.** **First, use create to
   157      expose a Private Port, which can be bound back to a Public Port a
   158      startup**:
   159  
   160          POST /containers/create HTTP/1.1
   161          Content-Type: application/json
   162  
   163          {
   164               "Cmd":[
   165                       "/usr/sbin/sshd","-D"
   166               ],
   167               "Image":"image-with-sshd",
   168               "ExposedPorts":{"22/tcp":{}}
   169               }
   170  
   171  **Example response**:
   172  
   173          HTTP/1.1 201 OK
   174          Content-Type: application/json
   175  
   176          {
   177               "Id":"e90e34656806"
   178               "Warnings":[]
   179          }
   180  
   181      **Second, start (using the ID returned above) the image we jus
   182      created, mapping the ssh port 22 to something on the host**:
   183  
   184          POST /containers/e90e34656806/start HTTP/1.1
   185          Content-Type: application/json
   186  
   187          {
   188               "PortBindings": { "22/tcp": [{ "HostPort": "11022" }]}
   189               }
   190  
   191  **Example response**:
   192  
   193          HTTP/1.1 204 No Conten
   194          Content-Type: text/plain; charset=utf-8
   195          Content-Length: 0
   196  
   197      **Now you can ssh into your new container on port 11022.**
   198  
   199  ### Inspect a container
   200  
   201  `GET /containers/(id)/json`
   202  
   203  Return low-level information on the container `id`
   204  
   205  
   206  **Example request**:
   207  
   208          GET /containers/4fa6e0f0c678/json HTTP/1.1
   209  
   210  **Example response**:
   211  
   212          HTTP/1.1 200 OK
   213          Content-Type: application/json
   214  
   215          {
   216                       "Id": "4fa6e0f0c6786287e131c3852c58a2e01cc697a68231826813597e4994f1d6e2",
   217                       "Created": "2013-05-07T14:51:42.041847+02:00",
   218                       "Path": "date",
   219                       "Args": [],
   220                       "Config": {
   221                               "Hostname": "4fa6e0f0c678",
   222                               "User": "",
   223                               "Memory": 0,
   224                               "MemorySwap": 0,
   225                               "AttachStdin": false,
   226                               "AttachStdout": true,
   227                               "AttachStderr": true,
   228                               "ExposedPorts": {},
   229                               "Tty": false,
   230                               "OpenStdin": false,
   231                               "StdinOnce": false,
   232                               "Env": null,
   233                               "Cmd": [
   234                                       "date"
   235                               ],
   236                               "Dns": null,
   237                               "Image": "base",
   238                               "Volumes": {},
   239                               "VolumesFrom": "",
   240                               "WorkingDir": ""
   241                       },
   242                       "State": {
   243                               "Running": false,
   244                               "Pid": 0,
   245                               "ExitCode": 0,
   246                               "StartedAt": "2013-05-07T14:51:42.087658+02:01360",
   247                               "Ghost": false
   248                       },
   249                       "Image": "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc",
   250                       "NetworkSettings": {
   251                               "IpAddress": "",
   252                               "IpPrefixLen": 0,
   253                               "Gateway": "",
   254                               "Bridge": "",
   255                               "PortMapping": null
   256                       },
   257                       "SysInitPath": "/home/kitty/go/src/github.com/docker/docker/bin/docker",
   258                       "ResolvConfPath": "/etc/resolv.conf",
   259                       "Volumes": {}
   260          }
   261  
   262  Status Codes:
   263  
   264  -   **200** – no error
   265  -   **404** – no such container
   266  -   **500** – server error
   267  
   268  ### List processes running inside a container
   269  
   270  `GET /containers/(id)/top`
   271  
   272  List processes running inside the container `id`
   273  
   274  **Example request**:
   275  
   276          GET /containers/4fa6e0f0c678/top HTTP/1.1
   277  
   278  **Example response**:
   279  
   280          HTTP/1.1 200 OK
   281          Content-Type: application/json
   282  
   283          {
   284               "Titles": [
   285                       "USER",
   286                       "PID",
   287                       "%CPU",
   288                       "%MEM",
   289                       "VSZ",
   290                       "RSS",
   291                       "TTY",
   292                       "STAT",
   293                       "START",
   294                       "TIME",
   295                       "COMMAND"
   296                       ],
   297               "Processes": [
   298                       ["root","20147","0.0","0.1","18060","1864","pts/4","S","10:06","0:00","bash"],
   299                       ["root","20271","0.0","0.0","4312","352","pts/4","S+","10:07","0:00","sleep","10"]
   300               ]
   301          }
   302  
   303  Query Parameters:
   304  
   305  -   **ps_args** – ps arguments to use (e.g., aux)
   306  
   307  Status Codes:
   308  
   309  -   **200** – no error
   310  -   **404** – no such container
   311  -   **500** – server error
   312  
   313  ### Inspect changes on a container's filesystem
   314  
   315  `GET /containers/(id)/changes`
   316  
   317  Inspect changes on container `id`'s filesystem
   318  
   319  **Example request**:
   320  
   321          GET /containers/4fa6e0f0c678/changes HTTP/1.1
   322  
   323  **Example response**:
   324  
   325          HTTP/1.1 200 OK
   326          Content-Type: application/json
   327  
   328          [
   329               {
   330                       "Path": "/dev",
   331                       "Kind": 0
   332               },
   333               {
   334                       "Path": "/dev/kmsg",
   335                       "Kind": 1
   336               },
   337               {
   338                       "Path": "/test",
   339                       "Kind": 1
   340               }
   341          ]
   342  
   343  Status Codes:
   344  
   345  -   **200** – no error
   346  -   **404** – no such container
   347  -   **500** – server error
   348  
   349  ### Export a container
   350  
   351  `GET /containers/(id)/export`
   352  
   353  Export the contents of container `id`
   354  
   355  **Example request**:
   356  
   357          GET /containers/4fa6e0f0c678/export HTTP/1.1
   358  
   359  **Example response**:
   360  
   361          HTTP/1.1 200 OK
   362          Content-Type: application/octet-stream
   363  
   364          {{ TAR STREAM }}
   365  
   366  Status Codes:
   367  
   368  -   **200** – no error
   369  -   **404** – no such container
   370  -   **500** – server error
   371  
   372  ### Start a container
   373  
   374  `POST /containers/(id)/start`
   375  
   376  Start the container `id`
   377  
   378  **Example request**:
   379  
   380          POST /containers/(id)/start HTTP/1.1
   381          Content-Type: application/json
   382  
   383          {
   384               "Binds":["/tmp:/tmp"],
   385               "LxcConf":[{"Key":"lxc.utsname","Value":"docker"}],
   386               "ContainerIDFile": "",
   387               "Privileged": false,
   388               "PortBindings": {"22/tcp": [{HostIp:"", HostPort:""}]},
   389               "Links": [],
   390               "PublishAllPorts": false
   391          }
   392  
   393  **Example response**:
   394  
   395          HTTP/1.1 204 No Content
   396          Content-Type: text/plain
   397  
   398  Json Parameters:
   399  
   400       
   401  
   402  -   **hostConfig** – the container's host configuration (optional)
   403  
   404  Status Codes:
   405  
   406  -   **204** – no error
   407  -   **404** – no such container
   408  -   **500** – server error
   409  
   410  ### Stop a container
   411  
   412  `POST /containers/(id)/stop`
   413  
   414  Stop the container `id`
   415  
   416  **Example request**:
   417  
   418          POST /containers/e90e34656806/stop?t=5 HTTP/1.1
   419  
   420  **Example response**:
   421  
   422          HTTP/1.1 204 OK
   423  
   424  Query Parameters:
   425  
   426  -   **t** – number of seconds to wait before killing the container
   427  
   428  Status Codes:
   429  
   430  -   **204** – no error
   431  -   **404** – no such container
   432  -   **500** – server error
   433  
   434  ### Restart a container
   435  
   436  `POST /containers/(id)/restart`
   437  
   438  Restart the container `id`
   439  
   440  **Example request**:
   441  
   442          POST /containers/e90e34656806/restart?t=5 HTTP/1.1
   443  
   444  **Example response**:
   445  
   446          HTTP/1.1 204 No Content
   447  
   448  Query Parameters:
   449  
   450  -   **t** – number of seconds to wait before killing the container
   451  
   452  Status Codes:
   453  
   454  -   **204** – no error
   455  -   **404** – no such container
   456  -   **500** – server error
   457  
   458  ### Kill a container
   459  
   460  `POST /containers/(id)/kill`
   461  
   462  Kill the container `id`
   463  
   464  **Example request**:
   465  
   466          POST /containers/e90e34656806/kill HTTP/1.1
   467  
   468  **Example response**:
   469  
   470          HTTP/1.1 204 No Content
   471  
   472  Query Parameters:
   473  
   474       
   475  
   476  -   **signal** – Signal to send to the container (integer). When no
   477          set, SIGKILL is assumed and the call will waits for the
   478          container to exit.
   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 byets
   564      4.  Read the extracted size and output it on the correct output
   565      5.  Goto 1)
   566  
   567  ### Wait a container
   568  
   569  `POST /containers/(id)/wait`
   570  
   571  Block until container `id` stops, then returns the exit code
   572  
   573  **Example request**:
   574  
   575          POST /containers/16253994b7c4/wait HTTP/1.1
   576  
   577  **Example response**:
   578  
   579          HTTP/1.1 200 OK
   580          Content-Type: application/json
   581  
   582          {"StatusCode": 0}
   583  
   584  Status Codes:
   585  
   586  -   **200** – no error
   587  -   **404** – no such container
   588  -   **500** – server error
   589  
   590  ### Remove a container
   591  
   592  `DELETE /containers/(id)`
   593  
   594  Remove the container `id` from the filesystem
   595  
   596  **Example request**:
   597  
   598          DELETE /containers/16253994b7c4?v=1 HTTP/1.1
   599  
   600  **Example response**:
   601  
   602          HTTP/1.1 204 No Content
   603  
   604  Query Parameters:
   605  
   606  -   **v** – 1/True/true or 0/False/false, Remove the volumes
   607          associated to the container. Default false
   608  
   609  Status Codes:
   610  
   611  -   **204** – no error
   612  -   **400** – bad parameter
   613  -   **404** – no such container
   614  -   **500** – server error
   615  
   616  ### Copy files or folders from a container
   617  
   618  `POST /containers/(id)/copy`
   619  
   620  Copy files or folders of container `id`
   621  
   622  **Example request**:
   623  
   624          POST /containers/4fa6e0f0c678/copy HTTP/1.1
   625          Content-Type: application/json
   626  
   627          {
   628               "Resource": "test.txt"
   629          }
   630  
   631  **Example response**:
   632  
   633          HTTP/1.1 200 OK
   634          Content-Type: application/octet-stream
   635  
   636          {{ TAR STREAM }}
   637  
   638  Status Codes:
   639  
   640  -   **200** – no error
   641  -   **404** – no such container
   642  -   **500** – server error
   643  
   644  ## 2.2 Images
   645  
   646  ### List Images
   647  
   648  `GET /images/(format)`
   649  
   650  List images `format` could be json or viz (json default)
   651  
   652  **Example request**:
   653  
   654          GET /images/json?all=0 HTTP/1.1
   655  
   656  **Example response**:
   657  
   658          HTTP/1.1 200 OK
   659          Content-Type: application/json
   660  
   661          [
   662               {
   663                       "Repository":"base",
   664                       "Tag":"ubuntu-12.10",
   665                       "Id":"b750fe79269d",
   666                       "Created":1364102658,
   667                       "Size":24653,
   668                       "VirtualSize":180116135
   669               },
   670               {
   671                       "Repository":"base",
   672                       "Tag":"ubuntu-quantal",
   673                       "Id":"b750fe79269d",
   674                       "Created":1364102658,
   675                       "Size":24653,
   676                       "VirtualSize":180116135
   677               }
   678          ]
   679  
   680  **Example request**:
   681  
   682          GET /images/viz HTTP/1.1
   683  
   684  **Example response**:
   685  
   686          HTTP/1.1 200 OK
   687          Content-Type: text/plain
   688  
   689          digraph docker {
   690          "d82cbacda43a" -> "074be284591f"
   691          "1496068ca813" -> "08306dc45919"
   692          "08306dc45919" -> "0e7893146ac2"
   693          "b750fe79269d" -> "1496068ca813"
   694          base -> "27cf78414709" [style=invis]
   695          "f71189fff3de" -> "9a33b36209ed"
   696          "27cf78414709" -> "b750fe79269d"
   697          "0e7893146ac2" -> "d6434d954665"
   698          "d6434d954665" -> "d82cbacda43a"
   699          base -> "e9aa60c60128" [style=invis]
   700          "074be284591f" -> "f71189fff3de"
   701          "b750fe79269d" [label="b750fe79269d\nbase",shape=box,fillcolor="paleturquoise",style="filled,rounded"];
   702          "e9aa60c60128" [label="e9aa60c60128\nbase2",shape=box,fillcolor="paleturquoise",style="filled,rounded"];
   703          "9a33b36209ed" [label="9a33b36209ed\ntest",shape=box,fillcolor="paleturquoise",style="filled,rounded"];
   704          base [style=invisible]
   705          }
   706  
   707  Query Parameters:
   708  
   709  -   **all** – 1/True/true or 0/False/false, Show all containers.
   710          Only running containers are shown by defaul
   711  
   712  Status Codes:
   713  
   714  -   **200** – no error
   715  -   **400** – bad parameter
   716  -   **500** – server error
   717  
   718  ### Create an image
   719  
   720  `POST /images/create`
   721  
   722  Create an image, either by pull it from the registry or by importing i
   723  
   724  **Example request**:
   725  
   726          POST /images/create?fromImage=base HTTP/1.1
   727  
   728  **Example response**:
   729  
   730          HTTP/1.1 200 OK
   731          Content-Type: application/json
   732  
   733          {"status":"Pulling..."}
   734          {"status":"Pulling", "progress":"1/? (n/a)"}
   735          {"error":"Invalid..."}
   736          ...
   737  
   738      When using this endpoint to pull an image from the registry, the
   739      `X-Registry-Auth` header can be used to include
   740      a base64-encoded AuthConfig object.
   741  
   742  Query Parameters:
   743  
   744  -   **fromImage** – name of the image to pull
   745  -   **fromSrc** – source to import, - means stdin
   746  -   **repo** – repository
   747  -   **tag** – tag
   748  -   **registry** – the registry to pull from
   749  
   750  Status Codes:
   751  
   752  -   **200** – no error
   753  -   **500** – server error
   754  
   755  ### Insert a file in an image
   756  
   757  `POST /images/(name)/insert`
   758  
   759  Insert a file from `url` in the image `name` at `path`
   760  
   761  **Example request**:
   762  
   763          POST /images/test/insert?path=/usr&url=myurl HTTP/1.1
   764  
   765  **Example response**:
   766  
   767          HTTP/1.1 200 OK
   768          Content-Type: application/json
   769  
   770          {"status":"Inserting..."}
   771          {"status":"Inserting", "progress":"1/? (n/a)"}
   772          {"error":"Invalid..."}
   773          ...
   774  
   775  Query Parameters:
   776  
   777  -	**url** – The url from where the file is taken
   778  -	**path** – The path where the file is stored
   779  
   780  Status Codes:
   781  
   782  -   **200** – no error
   783  -   **500** – server error
   784  
   785  ### Inspect an image
   786  
   787  `GET /images/(name)/json`
   788  
   789  Return low-level information on the image `name`
   790  
   791  **Example request**:
   792  
   793          GET /images/base/json HTTP/1.1
   794  
   795  **Example response**:
   796  
   797          HTTP/1.1 200 OK
   798          Content-Type: application/json
   799  
   800          {
   801               "id":"b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc",
   802               "parent":"27cf784147099545",
   803               "created":"2013-03-23T22:24:18.818426-07:00",
   804               "container":"3d67245a8d72ecf13f33dffac9f79dcdf70f75acb84d308770391510e0c23ad0",
   805               "container_config":
   806                       {
   807                               "Hostname":"",
   808                               "User":"",
   809                               "Memory":0,
   810                               "MemorySwap":0,
   811                               "AttachStdin":false,
   812                               "AttachStdout":false,
   813                               "AttachStderr":false,
   814                               "ExposedPorts":{},
   815                               "Tty":true,
   816                               "OpenStdin":true,
   817                               "StdinOnce":false,
   818                               "Env":null,
   819                               "Cmd": ["/bin/bash"],
   820                               "Dns":null,
   821                               "Image":"base",
   822                               "Volumes":null,
   823                               "VolumesFrom":"",
   824                               "WorkingDir":""
   825                       },
   826               "Size": 6824592
   827          }
   828  
   829  Status Codes:
   830  
   831  -   **200** – no error
   832  -   **404** – no such image
   833  -   **500** – server error
   834  
   835  ### Get the history of an image
   836  
   837  `GET /images/(name)/history`
   838  
   839  Return the history of the image `name`
   840  
   841  **Example request**:
   842  
   843          GET /images/base/history HTTP/1.1
   844  
   845  **Example response**:
   846  
   847          HTTP/1.1 200 OK
   848          Content-Type: application/json
   849  
   850          [
   851               {
   852                       "Id": "b750fe79269d",
   853                       "Created": 1364102658,
   854                       "CreatedBy": "/bin/bash"
   855               },
   856               {
   857                       "Id": "27cf78414709",
   858                       "Created": 1364068391,
   859                       "CreatedBy": ""
   860               }
   861          ]
   862  
   863  Status Codes:
   864  
   865  -   **200** – no error
   866  -   **404** – no such image
   867  -   **500** – server error
   868  
   869  ### Push an image on the registry
   870  
   871  `POST /images/(name)/push`
   872  
   873  Push the image `name` on the registry
   874  
   875  **Example request**:
   876  
   877          POST /images/test/push HTTP/1.1
   878  
   879  **Example response**:
   880  
   881          HTTP/1.1 200 OK
   882          Content-Type: application/json
   883  
   884      {"status":"Pushing..."} {"status":"Pushing", "progress":"1/? (n/a)"}
   885      {"error":"Invalid..."} ...
   886  
   887      > The `X-Registry-Auth` header can be used to
   888      > include a base64-encoded AuthConfig object.
   889  
   890  Status Codes:
   891  
   892  -   **200** – no error :statuscode 404: no such image :statuscode
   893          500: server error
   894  
   895  ### Tag an image into a repository
   896  
   897  `POST /images/(name)/tag`
   898  
   899  Tag the image `name` into a repository
   900  
   901  **Example request**:
   902  
   903          POST /images/test/tag?repo=myrepo&force=0&tag=v42 HTTP/1.1
   904  
   905  **Example response**:
   906  
   907          HTTP/1.1 201 OK
   908  
   909  Query Parameters:
   910  
   911  -   **repo** – The repository to tag in
   912  -   **force** – 1/True/true or 0/False/false, default false
   913  -   **tag** - The new tag name
   914  
   915  Status Codes:
   916  
   917  -   **201** – no error
   918  -   **400** – bad parameter
   919  -   **404** – no such image
   920  -   **409** – conflict
   921  -   **500** – server error
   922  
   923  ### Remove an image
   924  
   925  `DELETE /images/(name)`
   926  
   927  Remove the image `name` from the filesystem
   928  
   929  **Example request**:
   930  
   931          DELETE /images/test HTTP/1.1
   932  
   933  **Example response**:
   934  
   935          HTTP/1.1 200 OK
   936          Content-type: application/json
   937  
   938          [
   939           {"Untagged": "3e2f21a89f"},
   940           {"Deleted": "3e2f21a89f"},
   941           {"Deleted": "53b4f83ac9"}
   942          ]
   943  
   944  Status Codes:
   945  
   946  -   **200** – no error
   947  -   **404** – no such image
   948  -   **409** – conflict
   949  -   **500** – server error
   950  
   951  ### Search images
   952  
   953  `GET /images/search`
   954  
   955  Search for an image on [Docker Hub](https://hub.docker.com)
   956  
   957  **Example request**:
   958  
   959          GET /images/search?term=sshd HTTP/1.1
   960  
   961  **Example response**:
   962  
   963          HTTP/1.1 200 OK
   964          Content-Type: application/json
   965  
   966          [
   967               {
   968                       "Name":"cespare/sshd",
   969                       "Description":""
   970               },
   971               {
   972                       "Name":"johnfuller/sshd",
   973                       "Description":""
   974               },
   975               {
   976                       "Name":"dhrp/mongodb-sshd",
   977                       "Description":""
   978               }
   979          ]
   980  
   981          :query term: term to search
   982          :statuscode 200: no error
   983          :statuscode 500: server error
   984  
   985  ## 2.3 Misc
   986  
   987  ### Build an image from Dockerfile via stdin
   988  
   989  `POST /build`
   990  
   991  Build an image from Dockerfile via stdin
   992  
   993  **Example request**:
   994  
   995          POST /build HTTP/1.1
   996  
   997          {{ TAR STREAM }}
   998  
   999  **Example response**:
  1000  
  1001          HTTP/1.1 200 OK
  1002  
  1003          {{ STREAM }}
  1004  
  1005      The stream must be a tar archive compressed with one of the
  1006      following algorithms: identity (no compression), gzip, bzip2, xz.
  1007      The archive must include a file called Dockerfile at its root. I
  1008      may include any number of other files, which will be accessible in
  1009      the build context (See the ADD build command).
  1010  
  1011      The Content-type header should be set to "application/tar".
  1012  
  1013  Query Parameters:
  1014  
  1015  -   **t** – repository name (and optionally a tag) to be applied to
  1016      the resulting image in case of success
  1017  -   **q** – suppress verbose build output
  1018  -   **nocache** – do not use the cache when building the image
  1019  
  1020  Status Codes:
  1021  
  1022  -   **200** – no error
  1023  -   **500** – server error
  1024  
  1025  ### Check auth configuration
  1026  
  1027  `POST /auth`
  1028  
  1029  Get the default username and email
  1030  
  1031  **Example request**:
  1032  
  1033          POST /auth HTTP/1.1
  1034          Content-Type: application/json
  1035  
  1036          {
  1037               "username":" hannibal",
  1038               "password: "xxxx",
  1039               "email": "hannibal@a-team.com",
  1040               "serveraddress": "https://index.docker.io/v1/"
  1041          }
  1042  
  1043  **Example response**:
  1044  
  1045          HTTP/1.1 200 OK
  1046          Content-Type: text/plain
  1047  
  1048  Status Codes:
  1049  
  1050  -   **200** – no error
  1051  -   **204** – no error
  1052  -   **500** – server error
  1053  
  1054  ### Display system-wide information
  1055  
  1056  `GET /info`
  1057  
  1058  Display system-wide information
  1059  
  1060  **Example request**:
  1061  
  1062          GET /info HTTP/1.1
  1063  
  1064  **Example response**:
  1065  
  1066          HTTP/1.1 200 OK
  1067          Content-Type: application/json
  1068  
  1069          {
  1070               "Containers":11,
  1071               "Images":16,
  1072               "Debug":false,
  1073               "NFd": 11,
  1074               "NGoroutines":21,
  1075               "MemoryLimit":true,
  1076               "SwapLimit":false,
  1077               "IPv4Forwarding":true
  1078          }
  1079  
  1080  Status Codes:
  1081  
  1082  -   **200** – no error
  1083  -   **500** – server error
  1084  
  1085  ### Show the docker version information
  1086  
  1087  `GET /version`
  1088  
  1089  Show the docker version information
  1090  
  1091  **Example request**:
  1092  
  1093          GET /version HTTP/1.1
  1094  
  1095  **Example response**:
  1096  
  1097          HTTP/1.1 200 OK
  1098          Content-Type: application/json
  1099  
  1100          {
  1101               "Version":"0.2.2",
  1102               "GitCommit":"5a2a5cc+CHANGES",
  1103               "GoVersion":"go1.0.3"
  1104          }
  1105  
  1106  Status Codes:
  1107  
  1108  -   **200** – no error
  1109  -   **500** – server error
  1110  
  1111  ### Create a new image from a container's changes
  1112  
  1113  `POST /commit`
  1114  
  1115  Create a new image from a container's changes
  1116  
  1117  **Example request**:
  1118  
  1119          POST /commit?container=44c004db4b17&m=message&repo=myrepo HTTP/1.1
  1120          Content-Type: application/json
  1121  
  1122          {
  1123              "Cmd": ["cat", "/world"],
  1124              "ExposedPorts":{"22/tcp":{}}
  1125          }
  1126  
  1127  **Example response**:
  1128  
  1129          HTTP/1.1 201 OK
  1130              Content-Type: application/vnd.docker.raw-stream
  1131  
  1132          {"Id": "596069db4bf5"}
  1133  
  1134  Query Parameters:
  1135  
  1136  -   **container** – source container
  1137  -   **repo** – repository
  1138  -   **tag** – tag
  1139  -   **m** – commit message
  1140  -   **author** – author (e.g., "John Hannibal Smith
  1141          <[hannibal@a-team.com](mailto:hannibal%40a-team.com)>")
  1142  
  1143  Status Codes:
  1144  
  1145  -   **201** – no error
  1146  -   **404** – no such container
  1147  -   **500** – server error
  1148  
  1149  ### Monitor Docker's events
  1150  
  1151  `GET /events`
  1152  
  1153  Get events from docker, either in real time via streaming, or via
  1154  polling (using since).
  1155  
  1156  Docker containers will report the following events:
  1157  
  1158      create, destroy, die, export, kill, pause, restart, start, stop, unpause
  1159  
  1160  and Docker images will report:
  1161  
  1162      untag, delete
  1163  
  1164  **Example request**:
  1165  
  1166          GET /events?since=1374067924
  1167  
  1168  **Example response**:
  1169  
  1170          HTTP/1.1 200 OK
  1171          Content-Type: application/json
  1172  
  1173          {"status": "create", "id": "dfdf82bd3881","from": "base:latest", "time":1374067924}
  1174          {"status": "start", "id": "dfdf82bd3881","from": "base:latest", "time":1374067924}
  1175          {"status": "stop", "id": "dfdf82bd3881","from": "base:latest", "time":1374067966}
  1176          {"status": "destroy", "id": "dfdf82bd3881","from": "base:latest", "time":1374067970}
  1177  
  1178  Query Parameters:
  1179  
  1180  -   **since** – timestamp used for polling
  1181  
  1182  Status Codes:
  1183  
  1184  -   **200** – no error
  1185  -   **500** – server error
  1186  
  1187  # 3. Going further
  1188  
  1189  ## 3.1 Inside `docker run`
  1190  
  1191  Here are the steps of `docker run` :
  1192  
  1193  -   Create the container
  1194  
  1195  -   If the status code is 404, it means the image doesn't exist:
  1196          -   Try to pull it
  1197          -   Then retry to create the container
  1198  
  1199  -   Start the container
  1200  
  1201  -   If you are not in detached mode:
  1202          -   Attach to the container, using logs=1 (to have stdout and
  1203              stderr from the container's start) and stream=1
  1204  
  1205  -   If in detached mode or only stdin is attached:
  1206          -   Display the container's id
  1207  
  1208  ## 3.2 Hijacking
  1209  
  1210  In this version of the API, /attach, uses hijacking to transport stdin,
  1211  stdout and stderr on the same socket. This might change in the future.
  1212  
  1213  ## 3.3 CORS Requests
  1214  
  1215  To enable cross origin requests to the remote api add the flag
  1216  "--api-enable-cors" when running docker in daemon mode.
  1217  
  1218      $ docker -d -H="192.168.1.9:2375" --api-enable-cors