Skip to content

Docker

Build, run, inspect, and manage Docker containers.

6 modules

ModuleDescription
建置 Docker 映像檔從 Dockerfile 建置 Docker 映像檔
檢查 Docker 容器獲取 Docker 容器的詳細資訊
取得容器日誌從 Docker 容器取得日誌
列出 Docker 容器列出 Docker 容器
執行 Docker 容器從映像檔執行 Docker 容器
停止 Docker 容器停止正在執行的 Docker 容器

Modules

建置 Docker 映像檔

docker.build

從 Dockerfile 建置 Docker 映像檔

Parameters:

NameTypeRequiredDefaultDescription
pathstringYes-建置上下文目錄的路徑
tagstringYes-命名並選擇性地標記映像檔(例如:myapp:latest)
dockerfilestringNo-Dockerfile 的路徑(相對於建置上下文)
build_argsobjectNo-建置時的變數(例如:{"NODE_ENV": "production"})
no_cachebooleanNoFalse建置映像檔時不使用快取

Output:

FieldTypeDescription
image_idstring建置後的映像檔 ID
tagstring應用於映像檔的標籤
sizestring建置後的映像檔大小

Example: Build from current directory

yaml
path: .
tag: myapp:latest

Example: Build with custom Dockerfile and args

yaml
path: ./backend
tag: myapi:v1.0
dockerfile: Dockerfile.prod
build_args: {"NODE_ENV": "production"}
no_cache: true

檢查 Docker 容器

docker.inspect_container

獲取 Docker 容器的詳細資訊

Parameters:

NameTypeRequiredDefaultDescription
containerstringYes-要檢查的容器 ID 或名稱

Output:

FieldTypeDescription
idstring簡短的容器 ID
namestring容器名稱
stateobject容器狀態(狀態、運行中、pid、退出碼等)
imagestring容器使用的映像
network_settingsobject網路設定(IP、埠、網路)
mountsarray卷和綁定掛載
configobject容器設定(環境變數、命令、標籤等)

Example: Inspect a container by name

yaml
container: my-nginx

Example: Inspect a container by ID

yaml
container: a1b2c3d4e5f6

取得容器日誌

docker.logs

從 Docker 容器取得日誌

Parameters:

NameTypeRequiredDefaultDescription
containerstringYes-容器 ID 或名稱
tailnumberNo100從日誌結尾顯示的行數
followbooleanNoFalse跟隨日誌輸出(持續直到超時)
timestampsbooleanNoFalse在日誌輸出中顯示時間戳

Output:

FieldTypeDescription
logsstring容器日誌輸出
linesnumber返回的日誌行數

Example: Get last 50 lines

yaml
container: my-nginx
tail: 50

Example: Get logs with timestamps

yaml
container: my-app
tail: 100
timestamps: true

列出 Docker 容器

docker.ps

列出 Docker 容器

Parameters:

NameTypeRequiredDefaultDescription
allbooleanNoFalse顯示所有容器(預設僅顯示運行中的)
filtersobjectNo-篩選容器(例如:{"name": "my-app", "status": "running"})

Output:

FieldTypeDescription
containersarray包含 ID、名稱、映像、狀態、埠的容器列表
countnumber找到的容器數量

Example: List running containers

yaml

Example: List all containers

yaml
all: true

Example: Filter by name

yaml
filters: {"name": "nginx"}

執行 Docker 容器

docker.run

從映像檔執行 Docker 容器

Parameters:

NameTypeRequiredDefaultDescription
imagestringYes-要執行的 Docker 映像檔(例如:nginx:latest)
commandstringNo-在容器內執行的指令
namestringNo-為容器指定名稱
portsobjectNo-埠對應為主機:容器(例如:{"8080": "80"})
volumesobjectNo-卷對應為主機路徑:容器路徑
envobjectNo-在容器中設定的環境變數
detachbooleanNoTrue在背景執行容器
removebooleanNoFalse容器退出時自動移除
networkstringNo-將容器連接到網路

Output:

FieldTypeDescription
container_idstring建立的容器 ID
statusstring執行後的容器狀態

Example: Run Nginx web server

yaml
image: nginx:latest
name: my-nginx
ports: {"8080": "80"}
detach: true

Example: Run a one-off command

yaml
image: alpine:latest
command: echo hello world
remove: true
detach: false

停止 Docker 容器

docker.stop

停止正在執行的 Docker 容器

Parameters:

NameTypeRequiredDefaultDescription
containerstringYes-要停止的容器 ID 或名稱
timeoutnumberNo10在殺死容器前等待的秒數

Output:

FieldTypeDescription
container_idstring已停止的容器 ID 或名稱
stoppedboolean容器是否成功停止

Example: Stop a container by name

yaml
container: my-nginx

Example: Stop with custom timeout

yaml
container: my-app
timeout: 30

Released under the Apache 2.0 License.