Skip to content

Kubernetes Docker CLI API

kubectl 命令行工具,用于在 Kubernetes 集群上部署和检查应用。

1 class · 7 methods

Commands

7 methods

用于创建、查询、更新和调试 Kubernetes 资源的子命令。

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

创建或更新清单文件中定义的资源(声明式)。

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

列出一个或多个资源及其基本状态信息。

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]

显示特定资源的详细可读信息,包括事件。

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]

按文件、名称、标签选择器或 all 移除资源。

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]

打印容器日志。用 -f 跟随日志;当 pod 有多个容器时选择容器。

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...]

在 pod 的容器内执行命令。

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