1
0
mirror of https://github.com/docker/cli.git synced 2026-01-22 03:22:01 +03:00
Files
cli/components/engine/docs/sources/remote-api/api.rst
Victor Vieux 44910e43b1 update to master
Upstream-commit: 10c0e990371e065d4fc1c9b680f03a46e5bacc5e
Component: engine
2013-05-07 19:23:50 +02:00

16 KiB

Docker Remote API

Table of Contents

1. Brief introduction

  • The Remote API is replacing rcli
  • Default port in the docker deamon is 4243
  • The API tends to be REST, but for some complex commands, like attach or pull, the HTTP connection in hijacked to transport stdout stdin and stderr

2. Endpoints

2.1 Containers

List containers

List containers

Example request:

GET /containers?notrunc=1&all=1&quiet=0 HTTP/1.1

Example response:

HTTP/1.1 200 OK

[
 {
     "Id": "8dfafdbc3a40",
     "Image": "base:latest",
     "Command": "echo 1",
     "Created": 1367854155,
     "Status": "Exit 0"
 },
 {
     "Id": "9cd87474be90",
     "Image": "base:latest",
     "Command": "echo 2",
     "Created": 1367854155,
     "Status": "Exit 0"
 },
 {
     "Id": "3176a2479c92",
     "Image": "base:latest",
     "Command": "echo 3",
     "Created": 1367854154,
     "Status": "Exit 0"
 },
 {
     "Id": "4cb07b47f9fb",
     "Image": "base:latest",
     "Command": "echo 4",
     "Created": 1367854152,
     "Status": "Exit 0"
 }
]
query quiet
1 or 0, Only display numeric IDs. Not quiet by default
query all
1 or 0, Show all containers. Only running containers are shown by default
query notrunc
1 or 0, Don't truncate output. Output is truncated by default
query n
limit number, Show n last created containers, include non-running ones.
statuscode 200
no error
statuscode 500
server error

Create a container

Create a container

Example request:

POST /containers HTTP/1.1

{
 "Hostname":"",
 "User":"",
 "Memory":0,
 "MemorySwap":0,
 "AttachStdin":false,
 "AttachStdout":true,
 "AttachStderr":true,
 "PortSpecs":null,
 "Tty":false,
 "OpenStdin":false,
 "StdinOnce":false,
 "Env":null,
 "Cmd":[
     "date"
 ],
 "Dns":null,
 "Image":"base",
 "Volumes":{},
 "VolumesFrom":""
}

Example response:

HTTP/1.1 200 OK

{
 "Id":"e90e34656806"
 "Warnings":[]
}
jsonparam config
the container's configuration
statuscode 200
no error
statuscode 400
no such container
statuscode 500
server error

Inspect a container

Return low-level information on the container id

Example request:

GET /containers/4fa6e0f0c678 HTTP/1.1

Example response:

HTTP/1.1 200 OK

{
     "Id": "4fa6e0f0c6786287e131c3852c58a2e01cc697a68231826813597e4994f1d6e2",
     "Created": "2013-05-07T14:51:42.041847+02:00",
     "Path": "date",
     "Args": [],
     "Config": {
         "Hostname": "4fa6e0f0c678",
         "User": "",
         "Memory": 0,
         "MemorySwap": 0,
         "AttachStdin": false,
         "AttachStdout": true,
         "AttachStderr": true,
         "PortSpecs": null,
         "Tty": false,
         "OpenStdin": false,
         "StdinOnce": false,
         "Env": null,
         "Cmd": [
             "date"
         ],
         "Dns": null,
         "Image": "base",
         "Volumes": {},
         "VolumesFrom": ""
     },
     "State": {
         "Running": false,
         "Pid": 0,
         "ExitCode": 0,
         "StartedAt": "2013-05-07T14:51:42.087658+02:01360",
         "Ghost": false
     },
     "Image": "b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc",
     "NetworkSettings": {
         "IpAddress": "",
         "IpPrefixLen": 0,
         "Gateway": "",
         "Bridge": "",
         "PortMapping": null
     },
     "SysInitPath": "/home/kitty/go/src/github.com/dotcloud/docker/bin/docker",
     "ResolvConfPath": "/etc/resolv.conf",
     "Volumes": {}
}
statuscode 200
no error
statuscode 400
no such container
statuscode 500
server error

Inspect changes on a container's filesystem

Inspect changes on container id 's filesystem

Example request:

GET /containers/4fa6e0f0c678/changes HTTP/1.1

Example response:

HTTP/1.1 200 OK

[
     "C /dev",
     "A /dev/kmsg"
]
statuscode 200
no error
statuscode 400
no such container
statuscode 500
server error

Export a container

Export the contents of container id

Example request:

GET /containers/4fa6e0f0c678/export HTTP/1.1

Example response:

HTTP/1.1 200 OK
Content-Type: raw-stream-hijack

{{ STREAM }}
statuscode 200
no error
statuscode 400
no such container
statuscode 500
server error

Map container's private ports

Map a private port of container id

Example request:

GET /containers/4fa6e0f0c678/port?port=80 HTTP/1.1

Example response:

HTTP/1.1 200 OK

{"Port":"80"}
query port
the container private port you want to get
statuscode 200
no error
statuscode 400
no such container
statuscode 500
server error

Start a container

Start the container id

Example request:

POST /containers/e90e34656806/start HTTP/1.1

Example response:

HTTP/1.1 200 OK
statuscode 200
no error
statuscode 400
no such container
statuscode 500
server error

Stop a contaier

Stop the container id

Example request:

POST /containers/e90e34656806/stop?t=5 HTTP/1.1

Example response:

HTTP/1.1 200 OK
query t
number of seconds to wait before killing the container
statuscode 200
no error
statuscode 400
no such container
statuscode 500
server error

Restart a container

Restart the container id

Example request:

POST /containers/e90e34656806/restart?t=5 HTTP/1.1

Example response:

HTTP/1.1 200 OK
query t
number of seconds to wait before killing the container
statuscode 200
no error
statuscode 400
no such container
statuscode 500
server error

Kill a container

Kill the container id

Example request:

POST /containers/e90e34656806/kill HTTP/1.1

Example response:

HTTP/1.1 200 OK
statuscode 200
no error
statuscode 400
no such container
statuscode 500
server error

Attach to a container

Stop the container id

Example request:

POST /containers/16253994b7c4/attach?logs=1&stream=0&stdout=1 HTTP/1.1

Example response:

HTTP/1.1 200 OK
Content-Type: raw-stream-hijack

{{ STREAM }}
query logs
1 or 0, return logs. Default 0
query stream
1 or 0, return stream. Default 0
query stdin
1 or 0, if stream=1, attach to stdin. Default 0
query stdout
1 or 0, if logs=1, return stdout log, if stream=1, attach to stdout. Default 0
query stderr
1 or 0, if logs=1, return stderr log, if stream=1, attach to stderr. Default 0
statuscode 200
no error
statuscode 400
no such container
statuscode 500
server error

Wait a container

Block until container id stops, then returns the exit code

Example request:

POST /containers/16253994b7c4/wait HTTP/1.1

Example response:

HTTP/1.1 200 OK

{"StatusCode":0}
statuscode 200
no error
statuscode 400
no such container
statuscode 500
server error

Remove a container

Remove the container id from the filesystem

Example request:

DELETE /containers/16253994b7c4?v=1 HTTP/1.1

Example response:

HTTP/1.1 200 OK

query v
1 or 0, Remove the volumes associated to the container. Default 0 :statuscode 200: no error :statuscode 400: no such container :statuscode 500: server error

2.2 Images

List Images

List images

Example request:

GET /images?all=0&quiet=0 HTTP/1.1

Example response:

HTTP/1.1 200 OK

[
 {
     "Repository":"base",
     "Tag":"ubuntu-12.10",
     "Id":"b750fe79269d",
     "Created":1364102658
 },
 {
     "Repository":"base",
     "Tag":"ubuntu-quantal",
     "Id":"b750fe79269d",
     "Created":1364102658
 }
]
query quiet
1 or 0, Only display numeric IDs. Not quiet by default
query all
1 or 0, Show all containers. Only running containers are shown by default
statuscode 200
no error
statuscode 500
server error

Create an image

Create an image, either by pull it from the registry or by importing it

Example request:

POST /images?fromImage=base HTTP/1.1

Example response:

HTTP/1.1 200 OK

Content-Type: raw-stream-hijack

{{ STREAM }}

query fromImage
name of the image to pull
query fromSrc
source to import, - means stdin :query repo: repository
query tag
tag
query registry
the registry to pull from :statuscode 200: no error :statuscode 500: server error

Inspect an image

Return low-level information on the image name

Example request:

GET /images/base HTTP/1.1

Example response:

HTTP/1.1 200 OK

{ "id":"b750fe79269d2ec9a3c593ef05b4332b1d1a02a62b4accb2c21d589ff2f5f2dc", "parent":"27cf784147099545", "created":"2013-03-23T22:24:18.818426-07:00", "container":"3d67245a8d72ecf13f33dffac9f79dcdf70f75acb84d308770391510e0c23ad0", "container_config": { "Hostname":"", "User":"", "Memory":0, "MemorySwap":0, "AttachStdin":false, "AttachStdout":false, "AttachStderr":false, "PortSpecs":null, "Tty":true, "OpenStdin":true, "StdinOnce":false, "Env":null, "Cmd": ["/bin/bash"] ,"Dns":null, "Image":"base", "Volumes":null, "VolumesFrom":"" } }

statuscode 200
no error
statuscode 404
no such image :statuscode 500: server error

Get the history of an image

Return the history of the image name

Example request:

GET /images/base/history HTTP/1.1

Example response:

HTTP/1.1 200 OK
[

"Id":"b750fe79269d", "Created":1364102658, "CreatedBy":"/bin/bash"

}, { "Id":"27cf78414709", "Created":1364068391, "CreatedBy":"" } ]

statuscode 200
no error
statuscode 404
no such image
statuscode 500
server error

Push an image on the registry

Push the image name on the registry

Example request:

POST /images/test/push HTTP/1.1

Example response:

HTTP/1.1 200 OK

Content-Type: raw-stream-hijack

{{ STREAM }}

query registry
the registry you wan to push, optional
statuscode 200
no error :statuscode 404: no such image :statuscode 500: server error

Tag an image into a repository

Tag the image name into a repository

Example request:

POST /images/test/tag?repo=myrepo&force=0 HTTP/1.1

Example response:

HTTP/1.1 200 OK
query repo
The repository to tag in
query force
1 or 0, default 0
statuscode 200
no error
statuscode 404
no such image :statuscode 500: server error

Remove an image

Remove the image name from the filesystem

Example request:

DELETE /images/test HTTP/1.1

Example response:

HTTP/1.1 200 OK
statuscode 200
no error :statuscode 404: no such image :statuscode 500: server error

2.3 Misc

Get default username and email

Get the default username and email

Example request:

GET /auth HTTP/1.1

Example response:

HTTP/1.1 200 OK

{ "username":"hannibal", "email":"hannibal@a-team.com" }

statuscode 200
no error
statuscode 500
server error

Set auth configuration

Get the default username and email

Example request:

POST /auth HTTP/1.1

{ "username":"hannibal", "password:"xxxx", "email":"hannibal@a-team.com" }

Example response:

HTTP/1.1 200 OK
statuscode 200
no error
statuscode 500
server error

Display system-wide information

Display system-wide information

Example request:

GET /info HTTP/1.1

Example response:

HTTP/1.1 200 OK

{ "Containers":11, "Version":"0.2.2", "Images":16, "Debug":false }

statuscode 200
no error
statuscode 500
server error

Show the docker version information

Show the docker version information

Example request:

GET /version HTTP/1.1

Example response:

HTTP/1.1 200 OK

{ "Version":"0.2.2", "GitCommit":"5a2a5cc+CHANGES", "MemoryLimit":true, "SwapLimit":false }

statuscode 200
no error
statuscode 500
server error

Create a new image from a container's changes

Create a new image from a container's changes

Example request:

POST /commit?container=44c004db4b17&m=message&repo=myrepo HTTP/1.1

Example response:

HTTP/1.1 200 OK

Content-Type: raw-stream-hijack

{{ STREAM }}

query container
source container
query repo
repository
query tag
tag
query m
commit message
query author
author (eg. "John Hannibal Smith <hannibal@a-team.com>")
query run
config automatically applied when the image is run. (ex: {"Cmd": ["cat", "/world"], "PortSpecs":["22"]}) :statuscode 200: no error
statuscode 404
no such container :statuscode 500: server error

3. Going further

3.1 Inside 'docker run'

Here are the steps of 'docker run' :

  • Create the container
  • If the status code is 404, it means the image doesn't exists:
    • Try to pull it
    • Then retry to create the container
  • Start the container
  • If you are not in detached mode:
    • Attach to the container, using logs=1 (to have stdout and stderr from the container's start) and stream=1
    • Call /wait to get the exit code and exit with it

3.2 Hijacking

In this first version of the API, some of the endpoints, like /attach, /pull or /push uses hijacking to transport stdin, stdout and stderr on the same socket. This might change in the future.