Skip to content

Docker Docker CLI API

Docker command-line interface for building, shipping and running containers and images.

1 class · 7 methods

Commands

7 methods

Top-level docker subcommands for container and image lifecycle.

docker run [options] image [command] [args...]

Creates a new container from an image and starts it, running the given command.

Parameters

NameTypeDescription
optionsstringFlags such as -d (detached), -p (port), -v (volume), -e (env).
imagestringImage to run.
commandstringOptional command overriding the image CMD.

Returns

ContainerID

Example

docker
docker run -d -p 8080:80 --name web nginx:alpine
docker build [options] path | URL

Builds an image from a Dockerfile in the given path or URL.

Parameters

NameTypeDescription
optionsstringFlags such as -t (tag), --build-arg, --no-cache, --file.
pathstringBuild context path or URL.

Returns

void

Example

docker
docker build -t myapp:1.0 -f Dockerfile.prod .
docker pull [options] name[:tag]

Downloads an image from a registry and stores it locally.

Parameters

NameTypeDescription
namestringRepository name with optional registry prefix.
tagstringImage tag (defaults to latest).

Returns

void

Example

docker
docker pull postgres:16
docker push [options] name[:tag]

Uploads a local image to a registry.

Parameters

NameTypeDescription
namestringRepository name including registry namespace.
tagstringImage tag to push.

Returns

void

Example

docker
docker push ghcr.io/me/myapp:1.0
docker ps [options]

Lists containers. By default only running containers are shown.

Parameters

NameTypeDescription
optionsstringFlags such as -a (all), -q (ids only), --filter.

Returns

void

Example

docker
docker ps -a --filter "status=exited"
docker exec [options] container command [args...]

Runs a new command inside a running container.

Parameters

NameTypeDescription
optionsstringFlags such as -i (stdin), -t (tty), -u (user).
containerstringContainer name or id.
commandstringCommand to execute.

Returns

void

Example

docker
docker exec -it web sh
docker logs [options] container

Prints the stdout/stderr logs of a container.

Parameters

NameTypeDescription
optionsstringFlags such as -f (follow), --tail, --since, -t (timestamps).
containerstringContainer name or id.

Returns

void

Example

docker
docker logs -f --tail 100 web