Commands
7 methods用于创建、查询、更新和调试 Kubernetes 资源的子命令。
docker run [options] image [command] [args...]创建或更新清单文件中定义的资源(声明式)。
Parameters
| Name | Type | Description |
|---|---|---|
| options | string | Flags such as -d (detached), -p (port), -v (volume), -e (env). |
| image | string | Image to run. |
| command | string | Optional command overriding the image CMD. |
Returns
ContainerID
Example
docker
docker run -d -p 8080:80 --name web nginx:alpinedocker build [options] path | URL列出一个或多个资源及其基本状态信息。
Parameters
| Name | Type | Description |
|---|---|---|
| options | string | Flags such as -t (tag), --build-arg, --no-cache, --file. |
| path | string | Build context path or URL. |
Returns
void
Example
docker
docker build -t myapp:1.0 -f Dockerfile.prod .docker pull [options] name[:tag]显示特定资源的详细可读信息,包括事件。
Parameters
| Name | Type | Description |
|---|---|---|
| name | string | Repository name with optional registry prefix. |
| tag | string | Image tag (defaults to latest). |
Returns
void
Example
docker
docker pull postgres:16docker push [options] name[:tag]按文件、名称、标签选择器或 all 移除资源。
Parameters
| Name | Type | Description |
|---|---|---|
| name | string | Repository name including registry namespace. |
| tag | string | Image tag to push. |
Returns
void
Example
docker
docker push ghcr.io/me/myapp:1.0docker ps [options]打印容器日志。用 -f 跟随日志;当 pod 有多个容器时选择容器。
Parameters
| Name | Type | Description |
|---|---|---|
| options | string | Flags 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
| Name | Type | Description |
|---|---|---|
| options | string | Flags such as -i (stdin), -t (tty), -u (user). |
| container | string | Container name or id. |
| command | string | Command to execute. |
Returns
void
Example
docker
docker exec -it web shdocker logs [options] containerPrints the stdout/stderr logs of a container.
Parameters
| Name | Type | Description |
|---|---|---|
| options | string | Flags such as -f (follow), --tail, --since, -t (timestamps). |
| container | string | Container name or id. |
Returns
void
Example
docker
docker logs -f --tail 100 web