1. Brief introduction
- The Remote API has replaced
rcli
. - The daemon listens on
unix:///var/run/docker.sock
but you can Bind Docker to another host/port or a Unix socket. - The API tends to be REST. However, for some complex commands, like
attach
orpull
, the HTTP connection is hijacked to transportstdout
,stdin
andstderr
. - When the client API version is newer than the daemon’s, these calls return an HTTP
400 Bad Request
error message.
2. Errors
The Remote API uses standard HTTP status codes to indicate the success or failure of the API call. The body of the response will be JSON in the following format:
{
"message": "page not found" }
The status codes that are returned for each endpoint are specified in the endpoint documentation below.
3. Endpoints
3.1 Containers
List containers
GET /containers/json
List containers
Example request:
GET /containers/json?all=1&before=8dfafdbc3a40&size=1 HTTP/1.1
Example response:
HTTP/1.1 200 OK Content-Type: application/json [ { "Id": "8dfafdbc3a40", "Names":["/boring_feynman"], "Image": "ubuntu:latest", "ImageID": "d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82", "Command": "echo 1", "Created": 1367854155, "State": "Exited", "Status": "Exit 0", "Ports": [{"PrivatePort": 2222, "PublicPort": 3333, "Type": "tcp"}], "Labels": { "com.example.vendor": "Acme", "com.example.license": "GPL", "com.example.version": "1.0" }, "SizeRw": 12288, "SizeRootFs": 0, "HostConfig": { "NetworkMode": "default" }, "NetworkSettings": { "Networks": { "bridge": { "IPAMConfig": null, "Links": null, "Aliases": null, "NetworkID": "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812", "EndpointID": "2cdc4edb1ded3631c81f57966563e5c8525b81121bb3706a9a9a3ae102711f3f", "Gateway": "172.17.0.1", "IPAddress": "172.17.0.2", "IPPrefixLen": 16, "IPv6Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "MacAddress": "02:42:ac:11:00:02" } } }, "Mounts": [ { "Name": "fac362...80535", "Source": "/data", "Destination": "/data", "Driver": "local", "Mode": "ro,Z", "RW": false, "Propagation": "" } ] }, { "Id": "9cd87474be90", "Names":["/coolName"], "Image": "ubuntu:latest", "ImageID": "d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82", "Command": "echo 222222", "Created": 1367854155, "State": "Exited", "Status": "Exit 0", "Ports": [], "Labels": {}, "SizeRw": 12288, "SizeRootFs": 0, "HostConfig": { "NetworkMode": "default" }, "NetworkSettings": { "Networks": { "bridge": { "IPAMConfig": null, "Links": null, "Aliases": null, "NetworkID": "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812", "EndpointID": "88eaed7b37b38c2a3f0c4bc796494fdf51b270c2d22656412a2ca5d559a64d7a", "Gateway": "172.17.0.1", "IPAddress": "172.17.0.8", "IPPrefixLen": 16, "IPv6Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "MacAddress": "02:42:ac:11:00:08" } } }, "Mounts": [] }, { "Id": "3176a2479c92", "Names":["/sleepy_dog"], "Image": "ubuntu:latest", "ImageID": "d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82", "Command": "echo 3333333333333333", "Created": 1367854154, "State": "Exited", "Status": "Exit 0", "Ports":[], "Labels": {}, "SizeRw":12288, "SizeRootFs":0, "HostConfig": { "NetworkMode": "default" }, "NetworkSettings": { "Networks": { "bridge": { "IPAMConfig": null, "Links": null, "Aliases": null, "NetworkID": "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812", "EndpointID": "8b27c041c30326d59cd6e6f510d4f8d1d570a228466f956edf7815508f78e30d", "Gateway": "172.17.0.1", "IPAddress": "172.17.0.6", "IPPrefixLen": 16, "IPv6Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "MacAddress": "02:42:ac:11:00:06" } } }, "Mounts": [] }, { "Id": "4cb07b47f9fb", "Names":["/running_cat"], "Image": "ubuntu:latest", "ImageID": "d74508fb6632491cea586a1fd7d748dfc5274cd6fdfedee309ecdcbc2bf5cb82", "Command": "echo 444444444444444444444444444444444", "Created": 1367854152, "State": "Exited", "Status": "Exit 0", "Ports": [], "Labels": {}, "SizeRw": 12288, "SizeRootFs": 0, "HostConfig": { "NetworkMode": "default" }, "NetworkSettings": { "Networks": { "bridge": { "IPAMConfig": null, "Links": null, "Aliases": null, "NetworkID": "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812", "EndpointID": "d91c7b2f0644403d7ef3095985ea0e2370325cd2332ff3a3225c4247328e66e9", "Gateway": "172.17.0.1", "IPAddress": "172.17.0.5", "IPPrefixLen": 16, "IPv6Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "MacAddress": "02:42:ac:11:00:05" } } }, "Mounts": [] } ]
Query parameters:
- all – 1/True/true or 0/False/false, Show all containers. Only running containers are shown by default (i.e., this defaults to false)
- limit – Show
limit
last created containers, include non-running ones. - since – Show only containers created since Id, include non-running ones.
- before – Show only containers created before Id, include non-running ones.
- size – 1/True/true or 0/False/false, Show the containers sizes
- filters - a JSON encoded value of the filters (a
map[string][]string
) to process on the containers list. Available filters:exited=<int>
; -- containers with exit code of<int>
;status=
(created
|restarting
|running
|paused
|exited
|dead
)label=key
orlabel="key=value"
of a container labelisolation=
(default
|process
|hyperv
) (Windows daemon only)ancestor
=(<image-name>[:<tag>]
,<image id>
or<image@digest>
)before
=(<container id>
or<container name>
)since
=(<container id>
or<container name>
)volume
=(<volume name>
or<mount point destination>
)network
=(<network id>
or<network name>
)
Status codes:
- 200 – no error
- 400 – bad parameter
- 500 – server error
Create a container
POST /containers/create
Create a container
Example request:
POST /containers/create HTTP/1.1 Content-Type: application/json { "Hostname": "", "Domainname": "", "User": "", "AttachStdin": false, "AttachStdout": true, "AttachStderr": true, "Tty": false, "OpenStdin": false, "StdinOnce": false, "Env": [ "FOO=bar", "BAZ=quux" ], "Cmd": [ "date" ], "Entrypoint": "", "Image": "ubuntu", "Labels": { "com.example.vendor": "Acme", "com.example.license": "GPL", "com.example.version": "1.0" }, "Volumes": { "/volumes/data": {} }, "WorkingDir": "", "NetworkDisabled": false, "MacAddress": "12:34:56:78:9a:bc", "ExposedPorts": { "22/tcp": {} }, "StopSignal": "SIGTERM", "HostConfig": { "Binds": ["/tmp:/tmp"], "Links": ["redis3:redis"], "Memory": 0, "MemorySwap": 0, "MemoryReservation": 0, "KernelMemory": 0, "CpuPercent": 80, "CpuShares": 512, "CpuPeriod": 100000, "CpuQuota": 50000, "CpusetCpus": "0,1", "CpusetMems": "0,1", "MaximumIOps": 0, "MaximumIOBps": 0, "BlkioWeight": 300, "BlkioWeightDevice": [{}], "BlkioDeviceReadBps": [{}], "BlkioDeviceReadIOps": [{}], "BlkioDeviceWriteBps": [{}], "BlkioDeviceWriteIOps": [{}], "MemorySwappiness": 60, "OomKillDisable": false, "OomScoreAdj": 500, "PidMode": "", "PidsLimit": -1, "PortBindings": { "22/tcp": [{ "HostPort": "11022" }] }, "PublishAllPorts": false, "Privileged": false, "ReadonlyRootfs": false, "Dns": ["8.8.8.8"], "DnsOptions": [""], "DnsSearch": [""], "ExtraHosts": null, "VolumesFrom": ["parent", "other:ro"], "CapAdd": ["NET_ADMIN"], "CapDrop": ["MKNOD"], "GroupAdd": ["newgroup"], "RestartPolicy": { "Name": "", "MaximumRetryCount": 0 }, "NetworkMode": "bridge", "Devices": [], "Ulimits": [{}], "LogConfig": { "Type": "json-file", "Config": {} }, "SecurityOpt": [], "StorageOpt": {}, "CgroupParent": "", "VolumeDriver": "", "ShmSize": 67108864 }, "NetworkingConfig": { "EndpointsConfig": { "isolated_nw" : { "IPAMConfig": { "IPv4Address":"172.20.30.33", "IPv6Address":"2001:db8:abcd::3033", "LinkLocalIPs:["169.254.34.68", "fe80::3468"] }, "Links":["container_1", "container_2"], "Aliases":["server_x", "server_y"] } } }
Example response:
HTTP/1.1 201 Created Content-Type: application/json { "Id":"e90e34656806", "Warnings":[] }
JSON parameters:
- Hostname -主机名-包含主机名使用集装箱的字符串值 A string value containing the hostname to use for the container. This must be a valid RFC 1123 hostname.
- Domainname - 域名-包含用于容器的域名称的字符串值 A string value containing the domain name to use for the container.
- User - 指定容器内的用户 A string value specifying the user inside the container.
- AttachStdin - 布尔值,开放输入 Boolean value, attaches to
stdin
. - AttachStdout - 布尔值,高度标准 Boolean value, attaches to
stdout
. - AttachStderr - 布尔值, Boolean value, attaches to
stderr
. - Tty - 布尔值,附加标准流到终端 Boolean value, Attach standard streams to a
tty
, includingstdin
if it is not closed. - OpenStdin - 布尔值,打开标准输入 Boolean value, opens stdin,
- StdinOnce -布尔值,1连接的客户端断开后关闭标准输入 Boolean value, close
stdin
after the 1 attached client disconnects. - Env - 环境变量列表 A list of environment variables in the form of
["VAR=value"[,"VAR2=value2"]]
- Labels - 添加一个标签到容器 Adds a map of labels to a container. To specify a map:
{"key":"value"[,"key2":"value2"]}
- Cmd - 指定为字符串命令 Command to run specified as a string or an array of strings.
- Entrypoint 指定字符串命令所在目录 - Set the entry point for the container as a string or an array of strings.
- Image - 所属镜像 A string specifying the image name to use for the container.
- Volumes - 容器安装路径 An object mapping mount point paths (strings) inside the container to empty objects.
- WorkingDir - 字符串指定运行命令的工作目录 A string specifying the working directory for commands to run in.
- NetworkDisabled - 布尔值,是否正禁用网络 Boolean value, when true disables networking for the container
- ExposedPorts - 端口映射 An object mapping ports to an empty object in the form of:
"ExposedPorts": { "<port>/<tcp|udp>: {}" }
- StopSignal - 停止容器信号 Signal to stop a container as a string or unsigned integer.
SIGTERM
by default. - HostConfig
- Binds – A list of volume bindings for this container. Each volume binding is a string in one of these forms:
host_path:container_path
to bind-mount a host path into the containerhost_path:container_path:ro
to make the bind-mount read-only inside the container.volume_name:container_path
to bind-mount a volume managed by a volume plugin into the container.volume_name:container_path:ro
to make the bind mount read-only inside the container.
- Links - 容器的链接列表 A list of links for the container. Each link entry should be in the form of
container_name:alias
. - Memory - 内存-字节的内存限制 Memory limit in bytes.
- MemorySwap - 总内存限制(内存+交换) Total memory limit (memory + swap); set
-1
to enable unlimited swap. You must use this withmemory
and make the swap value larger thanmemory
. - MemoryReservation - 内存软限制的字节数 Memory soft limit in bytes.
- KernelMemory - 内核内存限制的字节数 Kernel memory limit in bytes.
- CpuPercent - 可用CPU百分比整数 An integer value containing the usable percentage of the available CPUs. (Windows daemon only)
- CpuShares - 容器的CPU比例 整型值 An integer value containing the container’s CPU Shares (ie. the relative weight vs other containers).
- CpuPeriod - 点用CPU周期的长度 The length of a CPU period in microseconds.
- CpuQuota - 微秒,容器可以使用的CPU周期 Microseconds of CPU time that the container can get in a CPU period.
- CpusetCpus - String value containing the
cgroups CpusetCpus
to use. - CpusetMems - Memory nodes (MEMs) in which to allow execution (0-3, 0,1). Only effective on NUMA systems.
- MaximumIOps - Maximum IO absolute rate in terms of IOps.
- MaximumIOBps - Maximum IO absolute rate in terms of bytes per second.
- BlkioWeight - Block IO weight (relative weight) accepts a weight value between 10 and 1000.
- BlkioWeightDevice - Block IO weight (relative device weight) in the form of:
"BlkioWeightDevice": [{"Path": "device_path", "Weight": weight}]
- BlkioDeviceReadBps - Limit read rate (bytes per second) from a device in the form of:
"BlkioDeviceReadBps": [{"Path": "device_path", "Rate": rate}]
, for example:"BlkioDeviceReadBps": [{"Path": "/dev/sda", "Rate": "1024"}]"
- BlkioDeviceWriteBps - Limit write rate (bytes per second) to a device in the form of:
"BlkioDeviceWriteBps": [{"Path": "device_path", "Rate": rate}]
, for example:"BlkioDeviceWriteBps": [{"Path": "/dev/sda", "Rate": "1024"}]"
- BlkioDeviceReadIOps - Limit read rate (IO per second) from a device in the form of:
"BlkioDeviceReadIOps": [{"Path": "device_path", "Rate": rate}]
, for example:"BlkioDeviceReadIOps": [{"Path": "/dev/sda", "Rate": "1000"}]
- BlkioDeviceWiiteIOps - Limit write rate (IO per second) to a device in the form of:
"BlkioDeviceWriteIOps": [{"Path": "device_path", "Rate": rate}]
, for example:"BlkioDeviceWriteIOps": [{"Path": "/dev/sda", "Rate": "1000"}]
- MemorySwappiness - Tune a container’s memory swappiness behavior. Accepts an integer between 0 and 100.
- OomKillDisable - Boolean value, whether to disable OOM Killer for the container or not.
- OomScoreAdj - An integer value containing the score given to the container in order to tune OOM killer preferences.
- PidMode - Set the PID (Process) Namespace mode for the container;
"container:<name|id>"
: joins another container’s PID namespace"host"
: use the host’s PID namespace inside the container - PidsLimit - Tune a container’s pids limit. Set -1 for unlimited.
- PortBindings - A map of exposed container ports and the host port they should map to. A JSON object in the form
{ <port>/<protocol>: [{ "HostPort": "<port>" }] }
Take note thatport
is specified as a string and not an integer value. - PublishAllPorts - Allocates a random host port for all of a container’s exposed ports. Specified as a boolean value.
- Privileged - Gives the container full access to the host. Specified as a boolean value.
- ReadonlyRootfs - Mount the container’s root filesystem as read only. Specified as a boolean value.
- Dns - A list of DNS servers for the container to use.
- DnsOptions - A list of DNS options
- DnsSearch - A list of DNS search domains
- ExtraHosts - A list of hostnames/IP mappings to add to the container’s
/etc/hosts
file. Specified in the form["hostname:IP"]
. - VolumesFrom - A list of volumes to inherit from another container. Specified in the form
<container name>[:<ro|rw>]
- CapAdd - A list of kernel capabilities to add to the container.
- Capdrop - A list of kernel capabilities to drop from the container.
- GroupAdd - A list of additional groups that the container process will run as
- RestartPolicy – The behavior to apply when the container exits. The value is an object with a
Name
property of either"always"
to always restart,"unless-stopped"
to restart always except when user has manually stopped the container or"on-failure"
to restart only when the container exit code is non-zero. Ifon-failure
is used,MaximumRetryCount
controls the number of times to retry before giving up. The default is not to restart. (optional) An ever increasing delay (double the previous delay, starting at 100mS) is added before each restart to prevent flooding the server. - UsernsMode - Sets the usernamespace mode for the container when usernamespace remapping option is enabled. supported values are:
host
. - NetworkMode - Sets the networking mode for the container. Supported standard values are:
bridge
,host
,none
, andcontainer:<name|id>
. Any other value is taken as a custom network’s name to which this container should connect to. - Devices - A list of devices to add to the container specified as a JSON object in the form
{ "PathOnHost": "/dev/deviceName", "PathInContainer": "/dev/deviceName", "CgroupPermissions": "mrw"}
- Ulimits - A list of ulimits to set in the container, specified as
{ "Name": <name>, "Soft": <soft limit>, "Hard": <hard limit> }
, for example:Ulimits: { "Name": "nofile", "Soft": 1024, "Hard": 2048 }
- Sysctls - A list of kernel parameters (sysctls) to set in the container, specified as
{ <name>: <Value> }
, for example:{ "net.ipv4.ip_forward": "1" }
- SecurityOpt: A list of string values to customize labels for MLS systems, such as SELinux.
- StorageOpt: Storage driver options per container. Options can be passed in the form
{"size":"120G"}
- LogConfig - Log configuration for the container, specified as a JSON object in the form
{ "Type": "<driver_name>", "Config": {"key1": "val1"}}
. Available types:json-file
,syslog
,journald
,gelf
,fluentd
,awslogs
,splunk
,etwlogs
,none
.json-file
logging driver. - CgroupParent - Path to
cgroups
under which the container’scgroup
is created. If the path is not absolute, the path is considered to be relative to thecgroups
path of the init process. Cgroups are created if they do not already exist. - VolumeDriver - Driver that this container users to mount volumes.
- ShmSize - Size of
/dev/shm
in bytes. The size must be greater than 0. If omitted the system uses 64MB.
- Binds – A list of volume bindings for this container. Each volume binding is a string in one of these forms:
Query parameters:
- name – Assign the specified name to the container. Must match
/?[a-zA-Z0-9_-]+
.
Status codes:
- 201 – no error
- 400 – bad parameter
- 404 – no such container
- 406 – impossible to attach (container not running)
- 409 – conflict
- 500 – server error
Inspect a container
GET /containers/(id or name)/json
Return low-level information on the container id
Example request:
GET /containers/4fa6e0f0c678/json HTTP/1.1
Example response:
HTTP/1.1 200 OK Content-Type: application/json { "AppArmorProfile": "", "Args": [ "-c", "exit 9" ], "Config": { "AttachStderr": true, "AttachStdin": false, "AttachStdout": true, "Cmd": [ "/bin/sh", "-c", "exit 9" ], "Domainname": "", "Entrypoint": null, "Env": [ "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ], "ExposedPorts": null, "Hostname": "ba033ac44011", "Image": "ubuntu", "Labels": { "com.example.vendor": "Acme", "com.example.license": "GPL", "com.example.version": "1.0" }, "MacAddress": "", "NetworkDisabled": false, "OnBuild": null, "OpenStdin": false, "StdinOnce": false, "Tty": false, "User": "", "Volumes": { "/volumes/data": {} }, "WorkingDir": "", "StopSignal": "SIGTERM" }, "Created": "2015-01-06T15:47:31.485331387Z", "Driver": "devicemapper", "ExecIDs": null, "HostConfig": { "Binds": null, "MaximumIOps": 0, "MaximumIOBps": 0, "BlkioWeight": 0, "BlkioWeightDevice": [{}], "BlkioDeviceReadBps": [{}], "BlkioDeviceWriteBps": [{}], "BlkioDeviceReadIOps": [{}], "BlkioDeviceWriteIOps": [{}], "CapAdd": null, "CapDrop": null, "ContainerIDFile": "", "CpusetCpus": "", "CpusetMems": "", "CpuPercent": 80, "CpuShares": 0, "CpuPeriod": 100000, "Devices": [], "Dns": null, "DnsOptions": null, "DnsSearch": null, "ExtraHosts": null, "IpcMode": "", "Links": null, "LxcConf": [], "Memory": 0, "MemorySwap": 0, "MemoryReservation": 0, "KernelMemory": 0, "OomKillDisable": false, "OomScoreAdj": 500, "NetworkMode": "bridge", "PidMode": "", "PortBindings": {}, "Privileged": false, "ReadonlyRootfs": false, "PublishAllPorts": false, "RestartPolicy": { "MaximumRetryCount": 2, "Name": "on-failure" }, "LogConfig": { "Config": null, "Type": "json-file" }, "SecurityOpt": null, "Sysctls": { "net.ipv4.ip_forward": "1" }, "StorageOpt": null, "VolumesFrom": null, "Ulimits": [{}], "VolumeDriver": "", "ShmSize": 67108864 }, "HostnamePath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/hostname", "HostsPath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/hosts", "LogPath": "/var/lib/docker/containers/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b-json.log", "Id": "ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39", "Image": "04c5d3b7b0656168630d3ba35d8889bd0e9caafcaeb3004d2bfbc47e7c5d35d2", "MountLabel": "", "Name": "/boring_euclid", "NetworkSettings": { "Bridge": "", "SandboxID": "", "HairpinMode": false, "LinkLocalIPv6Address": "", "LinkLocalIPv6PrefixLen": 0, "Ports": null, "SandboxKey": "", "SecondaryIPAddresses": null, "SecondaryIPv6Addresses": null, "EndpointID": "", "Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "IPAddress": "", "IPPrefixLen": 0, "IPv6Gateway": "", "MacAddress": "", "Networks": { "bridge": { "NetworkID": "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812", "EndpointID": "7587b82f0dada3656fda26588aee72630c6fab1536d36e394b2bfbcf898c971d", "Gateway": "172.17.0.1", "IPAddress": "172.17.0.2", "IPPrefixLen": 16, "IPv6Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "MacAddress": "02:42:ac:12:00:02" } } }, "Path": "/bin/sh", "ProcessLabel": "", "ResolvConfPath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/resolv.conf", "RestartCount": 1, "State": { "Error": "", "ExitCode": 9, "FinishedAt": "2015-01-06T15:47:32.080254511Z", "OOMKilled": false, "Dead": false, "Paused": false, "Pid": 0, "