Skip to content
@deckyard/docker

docker cheatsheet

Every export of @deckyard/docker. Guides are listed in the introduction.

jennifer
import "@deckyard/docker/" as docker;

Every failure of kind "docker" is a DockerError with the HTTP status (0 when there was no answer, 200 when the daemon reported the error inside a 2xx answer) and the daemon's own detail; a response over a cap is kind "limit", a deadline that passed kind "timeout", a connection closed mid-answer kind "closed", a cancelled task kind "cancelled", a network failure (refused, reset, unreachable, DNS, TLS) kind "net", the net.NetError that http threw. A JSON answer nested past the decoder's caps is kind "limit" too. A c argument is a Client; a ref is a container's (network's, image's) id or name; filters are name=value strings such as label=app=web; a query is a list of string of name=value parameters. Calls other than client, the with* settings, ping and version need an API version (negotiate or withApiVersion).

Constants

ConstantValueMeaning
VERSION"0.1.0"this deck's version
DEFAULT_TIMEOUT_MS30000the deadline of an ordinary request
DEFAULT_LONG_TIMEOUT_MS1800000the deadline of a pull, build or wait
DEFAULT_MAX_BYTES16777216the largest JSON response read
DEFAULT_MAX_STREAM_BYTES67108864the largest log, pull or build output read
MIN_API_VERSION"1.41"the oldest Engine API version the deck speaks
MAX_API_VERSION"1.56"the newest it knows; negotiate uses no newer one

The client

FunctionReturnsDoes
client(address)Clienta client for tcp://host[:port] or https://host[:port][/path]; unix:// is refused for now
negotiate(c)Clientask the daemon (GET /version) and use the lower of its API version and MAX_API_VERSION
withApiVersion(c, apiVersion)Clientpin an API version, 1.41 or later, without asking
withPlainHttp(c)Clientallow tcp:// to another machine (unauthenticated, root-equivalent)
withToken(c, token)Clientsend Authorization: Bearer to a socket proxy
withBasicAuth(c, username, password)Clientsend Authorization: Basic to a socket proxy
withTls(c, tls)Clientcertificate options for https (caCert, skipVerify)
withRegistryAuth(c, server, username, password)Clientsign pull in to a registry (X-Registry-Auth)
withTimeout(c, ms)Clientthe deadline of an ordinary request, 1000 to 86400000 ms
withLongTimeout(c, ms)Clientthe deadline of a pull, build or wait, 1000 to 86400000 ms
withMaxBytes(c, most)Clientthe largest JSON response, 65536 to 268435456 bytes
withMaxStreamBytes(c, most)Clientthe largest log or progress output, 65536 to 1073741824 bytes
call(c, method, path, query, body)json.Valueany other request, the path without the version (/containers/web/top)

Containers

FunctionReturnsDoes
containerSpec(image)ContainerSpeca spec for a container of an image
withCmd(spec, cmd)ContainerSpecthe command and its arguments
withEntrypoint(spec, entrypoint)ContainerSpecthe entrypoint
withEnv(spec, env)ContainerSpecenvironment variables (map of string to string); a name has no =, nothing a NUL
withLabels(spec, labels)ContainerSpeclabels; any key without control characters, values may span lines
withWorkingDir(spec, dir)ContainerSpecthe working directory, absolute
withUser(spec, user)ContainerSpecname, uid, name:group or uid:gid
withTty(spec, tty)ContainerSpeca terminal (its log is then one unframed stream)
withPort(spec, containerPort, hostIp, hostPort)ContainerSpecpublish 80 / 53/udp on a host address and port (0: the daemon picks)
withBind(spec, source, target, readOnly)ContainerSpecmount a host path or a named volume
withNetworkMode(spec, mode)ContainerSpecbridge, host, none, container:<ref> or a network
withRestartPolicy(spec, policy, maxRetries)ContainerSpecno, always, unless-stopped, on-failure
withAutoRemove(spec, autoRemove)ContainerSpecthe daemon removes it when it exits
withExtra(spec, extra)ContainerSpecmore of the create body in the API's names, merged over the rest
createContainer(c, name, spec)stringcreate (not start); the id. name "" lets the daemon pick
startContainer(c, ref)boolstart; false when it already ran
stopContainer(c, ref, seconds)boolSIGTERM, SIGKILL after seconds (-1: its own StopTimeout, one inspect); false when it was stopped
restartContainer(c, ref, seconds)boolstop as above, then start
killContainer(c, ref, signal)nullsend a signal (SIGKILL, HUP, SIGRTMIN+3, or 1 to 64)
removeContainer(c, ref, force, volumes)nullremove; force kills a running one, volumes takes its anonymous volumes
waitContainer(c, ref, condition)intwait (not-running, next-exit, removed) and return the exit code
containers(c, all, filters)list of Containerthe running ones, or all
inspectContainer(c, ref)ContainerInfoone in detail
logs(c, ref, query)Logsits log as stdout and stderr text (tail=100, since=..., timestamps=1; no follow)
logFrames(c, ref, query)list of LogFrameits log as frames in order, bytes as written
stats(c, ref)Statsone resource sample with the CPU share since the one before
exec(c, ref, cmd, env)stringrun a command detached in a running container; the exec id
inspectExec(c, id)Execwhether it runs, its exit code
waitExec(c, id)intwait for it to end (polled) and return its exit code

Images

FunctionReturnsDoes
pull(c, ref, platform)Pulledpull repository[:tag][@digest] (no tag: latest) and wait for it
tagImage(c, source, repo, tag)nullgive an image another name
removeImage(c, ref, force)list of stringremove an image or one of its names: untagged ... / deleted ... lines
build(c, files, tag, labels, query)Builtbuild from archive.Entry files (a tar context)
images(c, all, filters)list of Imagethe images (reference=alpine:*, dangling=true, ...)
inspectImage(c, ref)ImageInfoone in detail

Networks

FunctionReturnsDoes
createNetwork(c, name, driver, labels)stringcreate ("" driver: bridge); the id
removeNetwork(c, ref)nullremove
networks(c, filters)list of Networkthe networks, without their containers
inspectNetwork(c, ref)Networkone, with the containers on it
connectNetwork(c, network, container, aliases)nullput a container on a network
disconnectNetwork(c, network, container, force)nulltake it off

Volumes

FunctionReturnsDoes
createVolume(c, name, driver, labels)Volumecreate ("" driver: local)
removeVolume(c, name, force)nullremove
volumes(c, filters)list of Volumethe volumes
inspectVolume(c, name)Volumeone

System

FunctionReturnsDoes
ping(c)stringGET /_ping; the daemon's newest API version
version(c)Versionthe daemon's version (works before negotiate)
info(c)Infowhat the daemon reports about itself and its host
prune(c, what, filters)Prunedremove unused containers, images, networks, volumes or build cache

Types

Client

FieldMeaning
address as stringthe address as given
transport as stringtcp or https (unix reserved)
baseUrl as stringthe HTTP URL requests go to
apiVersion as stringthe API version in every path, "" until chosen
authorization as stringthe Authorization header for a proxy, "" for none
registryAuth as stringthe X-Registry-Auth header pull sends, "" for none
tls as http.TlsOptionscertificate checks for https
allowPlainHttp as booltcp:// to another machine allowed
timeoutMs as intthe deadline of an ordinary request
longTimeoutMs as intthe deadline of a pull, build or wait
maxBytes as intthe largest JSON response
maxStreamBytes as intthe largest log or progress output

DockerError

FieldMeaning
kind as stringalways "docker"
message as stringdocker: <request>: <why>, with (HTTP nnn) for an error status
status as intthe HTTP status; 200 for an error inside a 2xx answer; 0 without an answer
detail as stringthe daemon's own message, "" when none

ContainerSpec

FieldMeaning
image as stringthe image reference
cmd as list of stringthe command, empty for the image's
entrypoint as list of stringthe entrypoint, empty for the image's
env as map of string to stringenvironment variables
labels as map of string to stringlabels
workingDir as stringthe working directory
user as stringthe user
tty as boolwhether it gets a terminal
ports as list of PortBindingpublished ports
binds as list of stringmounts as source:target[:ro]
networkMode as stringthe network mode
restartPolicy as stringthe restart policy, "" for the default
maxRetries as inton-failure's retry count
autoRemove as boolremoved when it exits
extra as json.Valuemore of the create body, JSON null for none

PortBinding

FieldMeaning
containerPort as stringsuch as 80/tcp
hostIp as stringthe host address, "" for every address
hostPort as intthe host port, 0 for one the daemon picks

Container

FieldMeaning
id as stringthe full id
name as stringthe first name, without /
names as list of stringevery name
image as stringthe image as given
imageId as stringthe image id
command as stringthe command line
created as intUnix seconds
state as stringcreated, running, paused, restarting, exited, removing, dead
status as stringsuch as Up 2 hours
labels as map of string to stringits labels
ports as list of Portits ports
raw as json.Valuethe list entry

Port

FieldMeaning
ip as stringthe host address, "" when not published
privatePort as intthe port in the container
publicPort as intthe host port, 0 when not published
type as stringtcp, udp or sctp

ContainerInfo

FieldMeaning
id as stringthe full id
name as stringthe name, without /
image as stringthe image as given
imageId as stringthe image id
created as stringRFC 3339
status as stringthe state, as in Container.state
running as boolwhether it runs
paused as boolwhether it is paused
exitCode as intthe last exit code
error as stringwhy it last failed to start
oomKilled as boolkilled for memory
pid as intits main process, 0 when stopped
startedAt as stringRFC 3339
finishedAt as stringRFC 3339
restartCount as intrestarts by the daemon
tty as boolwhether it has a terminal
cmd as list of stringthe command
env as list of stringthe environment, KEY=value
labels as map of string to stringits labels
raw as json.Valuethe whole answer

LogFrame

FieldMeaning
stream as stringstdout or stderr
data as bytesthe bytes written

Logs

FieldMeaning
stdout as stringstandard output
stderr as stringstandard error ("" with a terminal)
tty as boolthe log came unframed, from a container with a terminal

Stats

FieldMeaning
read as stringwhen, RFC 3339
cpuPercent as floatCPU use, 100 per busy CPU
onlineCpus as intthe CPUs it can use
memoryUsage as intbytes, without the page cache
memoryLimit as intbytes
pids as intprocesses and threads
rxBytes as intbytes received
txBytes as intbytes sent
raw as json.Valuethe whole sample

Exec

FieldMeaning
id as stringthe exec id
containerId as stringits container
running as boolwhether it runs
exitCode as intits exit code once it ended
pid as intits process on the host (Podman: 0 once it ended)
cmd as list of stringthe command
raw as json.Valuethe whole answer

Image

FieldMeaning
id as stringsha256:<hex>
repoTags as list of stringits tags
repoDigests as list of stringits digests
created as intUnix seconds
size as intbytes
containers as intcontainers using it, -1 when not counted
labels as map of string to stringits labels
raw as json.Valuethe list entry

ImageInfo

FieldMeaning
id as stringsha256:<hex>
repoTags as list of stringits tags
repoDigests as list of stringits digests
created as stringRFC 3339
size as intbytes
architecture as stringsuch as amd64
os as stringsuch as linux
cmd as list of stringthe default command
entrypoint as list of stringthe entrypoint
env as list of stringthe environment
labels as map of string to stringits labels
raw as json.Valuethe whole answer

Pulled

FieldMeaning
image as stringthe reference pulled, with its tag
digest as stringthe manifest digest: from the progress, the reference, or one image inspect (Podman); "" when none has it
status as stringDocker's last Status: line; pulled when there was none (Podman)
lines as intprogress lines received

Built

FieldMeaning
id as stringthe new image's id
output as stringthe build output

Network

FieldMeaning
id as stringthe full id
name as stringits name
driver as stringsuch as bridge
scope as stringlocal or swarm
internal as boolno route out
created as stringRFC 3339
subnets as list of stringits subnets
labels as map of string to stringits labels
containers as list of stringcontainer ids on it (inspectNetwork only)
raw as json.Valuethe network as sent

Volume

FieldMeaning
name as stringits name
driver as stringsuch as local
mountpoint as stringwhere it lives on the host
scope as stringlocal or global
created as stringRFC 3339
labels as map of string to stringits labels
options as map of string to stringthe driver's options
raw as json.Valuethe volume as sent

Version

FieldMeaning
version as stringthe engine's version
apiVersion as stringits newest API version
minApiVersion as stringits oldest
os as stringsuch as linux
arch as stringsuch as amd64
kernelVersion as stringthe host's kernel
gitCommit as stringthe engine's commit
goVersion as stringthe Go it was built with
raw as json.Valuethe whole answer

Info

FieldMeaning
id as stringthe daemon's id
name as stringthe host name
serverVersion as stringthe engine's version
containers as intcontainers in every state
containersRunning as intrunning
containersPaused as intpaused
containersStopped as intstopped
images as intimages
driver as stringthe storage driver
operatingSystem as stringthe host's system
osType as stringlinux or windows
architecture as stringsuch as x86_64
ncpu as intCPUs
memTotal as intmemory, bytes
kernelVersion as stringthe host's kernel
dockerRootDir as stringwhere the daemon keeps its data
raw as json.Valuethe whole answer

Pruned

FieldMeaning
deleted as list of stringwhat was removed
spaceReclaimed as intbytes freed