github.com/pritambaral/docker@v1.4.2-0.20150120174542-b2fe1b3dd952/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  ### Wait a container
   561  
   562  `POST /containers/(id)/wait`
   563  
   564  Block until container `id` stops, then returns the exit code
   565  
   566  **Example request**:
   567  
   568          POST /containers/16253994b7c4/wait HTTP/1.1
   569  
   570  **Example response**:
   571  
   572          HTTP/1.1 200 OK
   573          Content-Type: application/json
   574  
   575          {"StatusCode": 0}
   576  
   577  Status Codes:
   578  
   579  -   **200** – no error
   580  -   **404** – no such container
   581  -   **500** – server error
   582  
   583  ### Remove a container
   584  
   585  `DELETE /containers/(id)`
   586  
   587  Remove the container `id` from the filesystem
   588  
   589  **Example request**:
   590  
   591          DELETE /containers/16253994b7c4?v=1 HTTP/1.1
   592  
   593  **Example response**:
   594  
   595          HTTP/1.1 204 No Content
   596  
   597  Query Parameters:
   598  
   599  -   **v** – 1/True/true or 0/False/false, Remove the volumes
   600          associated to the container. Default false
   601  
   602  Status Codes:
   603  
   604  -   **204** – no error
   605  -   **400** – bad parameter
   606  -   **404** – no such container
   607  -   **500** – server error
   608  
   609  ### Copy files or folders from a container
   610  
   611  `POST /containers/(id)/copy`
   612  
   613  Copy files or folders of container `id`
   614  
   615  **Example request**:
   616  
   617          POST /containers/4fa6e0f0c678/copy HTTP/1.1
   618          Content-Type: application/json
   619  
   620          {
   621               "Resource": "test.txt"
   622          }
   623  
   624  **Example response**:
   625  
   626          HTTP/1.1 200 OK
   627          Content-Type: application/octet-stream
   628  
   629          {{ TAR STREAM }}
   630  
   631  Status Codes:
   632  
   633  -   **200** – no error
   634  -   **404** – no such container
   635  -   **500** – server error
   636  
   637  ## 2.2 Images
   638  
   639  ### List Images
   640  
   641  `GET /images/json`
   642  
   643  **Example request**:
   644  
   645          GET /images/json?all=0 HTTP/1.1
   646  
   647  **Example response**:
   648  
   649          HTTP/1.1 200 OK
   650          Content-Type: application/json
   651  
   652          [
   653            {
   654               "RepoTags": [
   655                 "ubuntu:12.04",
   656                 "ubuntu:precise",
   657                 "ubuntu:latest"
   658               ],
   659               "Id": "8dbd9e392a964056420e5d58ca5cc376ef18e2de93b5cc90e868a1bbc8318c1c",
   660               "Created": 1365714795,
   661               "Size": 131506275,
   662               "VirtualSize": 131506275
   663            },
   664            {
   665               "RepoTags": [
   666                 "ubuntu:12.10",
   667                 "ubuntu:quantal"
   668               ],
   669               "ParentId": "27cf784147099545",
   670               "Id": "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc",
   671               "Created": 1364102658,
   672               "Size": 24653,
   673               "VirtualSize": 180116135
   674            }
   675          ]
   676  
   677  ### Create an image
   678  
   679  `POST /images/create`
   680  
   681  Create an image, either by pull it from the registry or by importing i
   682  
   683  **Example request**:
   684  
   685          POST /images/create?fromImage=base HTTP/1.1
   686  
   687  **Example response**:
   688  
   689          HTTP/1.1 200 OK
   690          Content-Type: application/json
   691  
   692          {"status": "Pulling..."}
   693          {"status": "Pulling", "progress": "1 B/ 100 B", "progressDetail": {"current": 1, "total": 100}}
   694          {"error": "Invalid..."}
   695          ...
   696  
   697      When using this endpoint to pull an image from the registry, the
   698      `X-Registry-Auth` header can be used to include
   699      a base64-encoded AuthConfig object.
   700  
   701  Query Parameters:
   702  
   703  -   **fromImage** – name of the image to pull
   704  -   **fromSrc** – source to import, - means stdin
   705  -   **repo** – repository
   706  -   **tag** – tag
   707  -   **registry** – the registry to pull from
   708  
   709  Request Headers:
   710  
   711  -   **X-Registry-Auth** – base64-encoded AuthConfig object
   712  
   713  Status Codes:
   714  
   715  -   **200** – no error
   716  -   **500** – server error
   717  
   718  ### Insert a file in an image
   719  
   720  `POST /images/(name)/insert`
   721  
   722  Insert a file from `url` in the image `name` at `path`
   723  
   724  **Example request**:
   725  
   726          POST /images/test/insert?path=/usr&url=myurl HTTP/1.1
   727  
   728  **Example response**:
   729  
   730          HTTP/1.1 200 OK
   731          Content-Type: application/json
   732  
   733          {"status":"Inserting..."}
   734          {"status":"Inserting", "progress":"1/? (n/a)", "progressDetail":{"current":1}}
   735          {"error":"Invalid..."}
   736          ...
   737  
   738  Query Parameters:
   739  
   740  -	**url** – The url from where the file is taken
   741  -	**path** – The path where the file is stored
   742  
   743  Status Codes:
   744  
   745  -   **200** – no error
   746  -   **500** – server error
   747  
   748  ### Inspect an image
   749  
   750  `GET /images/(name)/json`
   751  
   752  Return low-level information on the image `name`
   753  
   754  **Example request**:
   755  
   756          GET /images/base/json HTTP/1.1
   757  
   758  **Example response**:
   759  
   760          HTTP/1.1 200 OK
   761          Content-Type: application/json
   762  
   763          {
   764               "id":"b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc",
   765               "parent":"27cf784147099545",
   766               "created":"2013-03-23T22:24:18.818426-07:00",
   767               "container":"3d67245a8d72ecf13f33dffac9f79dcdf70f75acb84d308770391510e0c23ad0",
   768               "container_config":
   769                       {
   770                               "Hostname":"",
   771                               "User":"",
   772                               "Memory":0,
   773                               "MemorySwap":0,
   774                               "AttachStdin":false,
   775                               "AttachStdout":false,
   776                               "AttachStderr":false,
   777                               "PortSpecs":null,
   778                               "Tty":true,
   779                               "OpenStdin":true,
   780                               "StdinOnce":false,
   781                               "Env":null,
   782                               "Cmd": ["/bin/bash"],
   783                               "Dns":null,
   784                               "Image":"base",
   785                               "Volumes":null,
   786                               "VolumesFrom":"",
   787                               "WorkingDir":""
   788                       },
   789               "Size": 6824592
   790          }
   791  
   792  Status Codes:
   793  
   794  -   **200** – no error
   795  -   **404** – no such image
   796  -   **500** – server error
   797  
   798  ### Get the history of an image
   799  
   800  `GET /images/(name)/history`
   801  
   802  Return the history of the image `name`
   803  
   804  **Example request**:
   805  
   806          GET /images/base/history HTTP/1.1
   807  
   808  **Example response**:
   809  
   810          HTTP/1.1 200 OK
   811          Content-Type: application/json
   812  
   813          [
   814               {
   815                       "Id": "b750fe79269d",
   816                       "Created": 1364102658,
   817                       "CreatedBy": "/bin/bash"
   818               },
   819               {
   820                       "Id": "27cf78414709",
   821                       "Created": 1364068391,
   822                       "CreatedBy": ""
   823               }
   824          ]
   825  
   826  Status Codes:
   827  
   828  -   **200** – no error
   829  -   **404** – no such image
   830  -   **500** – server error
   831  
   832  ### Push an image on the registry
   833  
   834  `POST /images/(name)/push`
   835  
   836  Push the image `name` on the registry
   837  
   838  **Example request**:
   839  
   840          POST /images/test/push HTTP/1.1
   841  
   842  **Example response**:
   843  
   844          HTTP/1.1 200 OK
   845          Content-Type: application/json
   846  
   847          {"status": "Pushing..."}
   848          {"status": "Pushing", "progress": "1/? (n/a)", "progressDetail": {"current": 1}}}
   849          {"error": "Invalid..."}
   850          ...
   851  
   852      Request Headers:
   853  
   854       
   855  
   856  -   **X-Registry-Auth** – include a base64-encoded AuthConfig
   857          object.
   858  
   859  Status Codes:
   860  
   861  -   **200** – no error
   862  -   **404** – no such image
   863  -   **500** – server error
   864  
   865  ### Tag an image into a repository
   866  
   867  `POST /images/(name)/tag`
   868  
   869  Tag the image `name` into a repository
   870  
   871  **Example request**:
   872  
   873          POST /images/test/tag?repo=myrepo&force=0&tag=v42 HTTP/1.1
   874  
   875  **Example response**:
   876  
   877          HTTP/1.1 201 OK
   878  
   879  Query Parameters:
   880  
   881  -   **repo** – The repository to tag in
   882  -   **force** – 1/True/true or 0/False/false, default false
   883  -   **tag** - The new tag name
   884  
   885  Status Codes:
   886  
   887  -   **201** – no error
   888  -   **400** – bad parameter
   889  -   **404** – no such image
   890  -   **409** – conflict
   891  -   **500** – server error
   892  
   893  ### Remove an image
   894  
   895  `DELETE /images/(name)`
   896  
   897  Remove the image `name` from the filesystem
   898  
   899  **Example request**:
   900  
   901          DELETE /images/test HTTP/1.1
   902  
   903  **Example response**:
   904  
   905          HTTP/1.1 200 OK
   906          Content-type: application/json
   907  
   908          [
   909           {"Untagged": "3e2f21a89f"},
   910           {"Deleted": "3e2f21a89f"},
   911           {"Deleted": "53b4f83ac9"}
   912          ]
   913  
   914  Status Codes:
   915  
   916  -   **200** – no error
   917  -   **404** – no such image
   918  -   **409** – conflict
   919  -   **500** – server error
   920  
   921  ### Search images
   922  
   923  `GET /images/search`
   924  
   925  Search for an image on [Docker Hub](https://hub.docker.com).
   926  
   927  > **Note**:
   928  > The response keys have changed from API v1.6 to reflect the JSON
   929  > sent by the registry server to the docker daemon's request.
   930  
   931  **Example request**:
   932  
   933          GET /images/search?term=sshd HTTP/1.1
   934  
   935  **Example response**:
   936  
   937          HTTP/1.1 200 OK
   938          Content-Type: application/json
   939  
   940          [
   941                  {
   942                      "description": "",
   943                      "is_official": false,
   944                      "is_trusted": false,
   945                      "name": "wma55/u1210sshd",
   946                      "star_count": 0
   947                  },
   948                  {
   949                      "description": "",
   950                      "is_official": false,
   951                      "is_trusted": false,
   952                      "name": "jdswinbank/sshd",
   953                      "star_count": 0
   954                  },
   955                  {
   956                      "description": "",
   957                      "is_official": false,
   958                      "is_trusted": false,
   959                      "name": "vgauthier/sshd",
   960                      "star_count": 0
   961                  }
   962          ...
   963          ]
   964  
   965  Query Parameters:
   966  
   967  -   **term** – term to search
   968  
   969  Status Codes:
   970  
   971  -   **200** – no error
   972  -   **500** – server error
   973  
   974  ## 2.3 Misc
   975  
   976  ### Build an image from Dockerfile via stdin
   977  
   978  `POST /build`
   979  
   980  Build an image from Dockerfile via stdin
   981  
   982  **Example request**:
   983  
   984          POST /build HTTP/1.1
   985  
   986          {{ TAR STREAM }}
   987  
   988  **Example response**:
   989  
   990          HTTP/1.1 200 OK
   991          Content-Type: application/json
   992  
   993          {"stream": "Step 1..."}
   994          {"stream": "..."}
   995          {"error": "Error...", "errorDetail": {"code": 123, "message": "Error..."}}
   996  
   997      The stream must be a tar archive compressed with one of the
   998      following algorithms: identity (no compression), gzip, bzip2, xz.
   999  
  1000      The archive must include a file called `Dockerfile`
  1001      at its root. It may include any number of other files,
  1002      which will be accessible in the build context (See the [*ADD build
  1003      command*](/reference/builder/#dockerbuilder)).
  1004  
  1005  Query Parameters:
  1006  
  1007  -   **t** – repository name (and optionally a tag) to be applied to
  1008      the resulting image in case of success
  1009  -   **q** – suppress verbose build output
  1010  -   **nocache** – do not use the cache when building the image
  1011  
  1012      Request Headers:
  1013  
  1014       
  1015  
  1016  -   **Content-type** – should be set to
  1017          `"application/tar"`.
  1018  -   **X-Registry-Auth** – base64-encoded AuthConfig objec
  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  
  1121  **Example response**:
  1122  
  1123          HTTP/1.1 201 OK
  1124              Content-Type: application/vnd.docker.raw-stream
  1125  
  1126          {"Id": "596069db4bf5"}
  1127  
  1128  Query Parameters:
  1129  
  1130  -   **container** – source container
  1131  -   **repo** – repository
  1132  -   **tag** – tag
  1133  -   **m** – commit message
  1134  -   **author** – author (e.g., "John Hannibal Smith
  1135          <[hannibal@a-team.com](mailto:hannibal%40a-team.com)>")
  1136  -   **run** – config automatically applied when the image is run.
  1137          (ex: {"Cmd": ["cat", "/world"], "PortSpecs":["22"]})
  1138  
  1139  Status Codes:
  1140  
  1141  -   **201** – no error
  1142  -   **404** – no such container
  1143  -   **500** – server error
  1144  
  1145  ### Monitor Docker's events
  1146  
  1147  `GET /events`
  1148  
  1149  Get events from docker, either in real time via streaming,
  1150  or via polling (using since).
  1151  
  1152  Docker containers will report the following events:
  1153  
  1154      create, destroy, die, export, kill, pause, restart, start, stop, unpause
  1155  
  1156  and Docker images will report:
  1157  
  1158      untag, delete
  1159  
  1160  **Example request**:
  1161  
  1162          GET /events?since=1374067924
  1163  
  1164  **Example response**:
  1165  
  1166          HTTP/1.1 200 OK
  1167          Content-Type: application/json
  1168  
  1169          {"status": "create", "id": "dfdf82bd3881","from": "base:latest", "time":1374067924}
  1170          {"status": "start", "id": "dfdf82bd3881","from": "base:latest", "time":1374067924}
  1171          {"status": "stop", "id": "dfdf82bd3881","from": "base:latest", "time":1374067966}
  1172          {"status": "destroy", "id": "dfdf82bd3881","from": "base:latest", "time":1374067970}
  1173  
  1174  Query Parameters:
  1175  
  1176  -   **since** – timestamp used for polling
  1177  
  1178  Status Codes:
  1179  
  1180  -   **200** – no error
  1181  -   **500** – server error
  1182  
  1183  ### Get a tarball containing all images and tags in a repository
  1184  
  1185  `GET /images/(name)/get`
  1186  
  1187  Get a tarball containing all images and metadata for the repository
  1188  specified by `name`.
  1189  See the [image tarball format](#image-tarball-format) for more details.
  1190  
  1191  **Example request**
  1192  
  1193          GET /images/ubuntu/get
  1194  
  1195  **Example response**:
  1196  
  1197          HTTP/1.1 200 OK
  1198          Content-Type: application/x-tar
  1199  
  1200          Binary data stream
  1201  
  1202  Status Codes:
  1203  
  1204  -   **200** – no error
  1205  -   **500** – server error
  1206  
  1207  ### Load a tarball with a set of images and tags into docker
  1208  
  1209  `POST /images/load`
  1210  
  1211  Load a set of images and tags into the docker repository.
  1212  
  1213  See the [image tarball format](#image-tarball-format) for more details.
  1214  
  1215  **Example request**
  1216  
  1217          POST /images/load
  1218  
  1219          Tarball in body
  1220  
  1221  **Example response**:
  1222  
  1223          HTTP/1.1 200 OK
  1224  
  1225  Status Codes:
  1226  
  1227  -   **200** – no error
  1228  -   **500** – server error
  1229  
  1230  ### Image tarball format
  1231  
  1232  An image tarball contains one directory per image layer (named using its long ID),
  1233  each containing three files:
  1234  
  1235  1. `VERSION`: currently `1.0` - the file format version
  1236  2. `json`: detailed layer information, similar to `docker inspect layer_id`
  1237  3. `layer.tar`: A tarfile containing the filesystem changes in this layer
  1238  
  1239  The `layer.tar` file will contain `aufs` style `.wh..wh.aufs` files and directories
  1240  for storing attribute changes and deletions.
  1241  
  1242  If the tarball defines a repository, there will also be a `repositories` file at
  1243  the root that contains a list of repository and tag names mapped to layer IDs.
  1244  
  1245  ```
  1246  {"hello-world":
  1247      {"latest": "565a9d68a73f6706862bfe8409a7f659776d4d60a8d096eb4a3cbce6999cc2a1"}
  1248  }
  1249  ```
  1250  
  1251  # 3. Going further
  1252  
  1253  ## 3.1 Inside `docker run`
  1254  
  1255  Here are the steps of `docker run`:
  1256  
  1257   - Create the container
  1258  
  1259   - If the status code is 404, it means the image doesn't exist:
  1260          - Try to pull it
  1261          - Then retry to create the container
  1262  
  1263   - Start the container
  1264  
  1265   - If you are not in detached mode:
  1266          - Attach to the container, using logs=1 (to have stdout and
  1267              stderr from the container's start) and stream=1
  1268  
  1269   - If in detached mode or only stdin is attached:
  1270          - Display the container's id
  1271  
  1272  ## 3.2 Hijacking
  1273  
  1274  In this version of the API, /attach, uses hijacking to transport stdin,
  1275  stdout and stderr on the same socket. This might change in the future.
  1276  
  1277  ## 3.3 CORS Requests
  1278  
  1279  To enable cross origin requests to the remote api add the flag
  1280  "--api-enable-cors" when running docker in daemon mode.
  1281  
  1282      $ docker -d -H="192.168.1.9:2375" --api-enable-cors