Docker Remote Skill
Remotely manage Docker Compose instances through SSH connections.
Overview
This skill provides a complete set of actions for Docker Compose lifecycle management on remote servers. All operations are performed via SSH, requiring only standard SSH and Docker tools on both client and server.
Quick Start
CODEBLOCK0
Actions
dockercomposeup
Start Docker Compose services in detached mode.
Parameters:
- -
host (required): Remote SSH host (IP or hostname) - INLINECODE1 (required): SSH username
- INLINECODE2 (required): Directory containing docker-compose.yml
- INLINECODE3 (optional, default: 22): SSH port
- INLINECODE4 (optional): SSH private key path
- INLINECODE5 (optional, default: 60): Operation timeout in seconds
Example:
CODEBLOCK1
dockercomposedown
Stop and remove containers, networks, and volumes defined in docker-compose.yml.
Parameters: Same as INLINECODE6
Example:
CODEBLOCK2
dockercomposestart
Start specific stopped services.
Parameters:
- - All
up parameters - INLINECODE8 (optional): Service name to start (starts all if not specified)
Example:
CODEBLOCK3
dockercomposestop
Stop running services without removing them.
Parameters:
- - All
up parameters - INLINECODE10 (optional): Service name to stop (stops all if not specified)
Example:
CODEBLOCK4
dockercomposerestart
Restart services.
Parameters:
- - All
up parameters - INLINECODE12 (optional): Service name to restart
Example:
CODEBLOCK5
dockercomposeps
List all containers with their status.
Parameters: Same as INLINECODE13
Example:
CODEBLOCK6
dockercomposelogs
Fetch and display logs from services.
Parameters:
- - All
up parameters - INLINECODE15 (optional): Filter logs to specific service
- INLINECODE16 (optional, default: 100): Number of lines to show
- INLINECODE17 (optional, default: false): Stream logs continuously
Example:
CODEBLOCK7
dockercomposeupdate
Pull the latest images and restart services.
Parameters:
- - All
up parameters - INLINECODE19 (optional, default: false): Force recreate containers
- INLINECODE20 (optional): Image pull policy (never, always, missing)
- INLINECODE21 (optional): Custom command to execute instead of default "pull && up"
Example:
CODEBLOCK8
dockercomposeexec
Execute a command in a running container.
Parameters:
- - All
up parameters - INLINECODE23 (required): Container name to execute in
- INLINECODE24 (required): Command to execute
- INLINECODE25 (optional, default: 60): Command execution timeout
Example:
CODEBLOCK9
Implementation Notes
- - SSH connections use key-based authentication by default
- Always change to the correct directory before running docker compose commands
- Use
-d flag for detached mode when starting services - Handle SSH connection timeouts and authentication failures gracefully
- Return structured output with success/failure status and relevant logs
- Include error context when operations fail
Error Handling
Common errors and handling:
- 1. SSH connection refused: Verify host, port, and network access
- Authentication failed: Check SSH key path and permissions
- Path not found: Ensure docker-compose.yml exists at specified path
- Docker not running: Verify Docker daemon is accessible on remote host
- Permission denied: Check user has access to Docker socket
Deployment Configuration
This skill supports a deploy-apps.json configuration file that maps your remote hosts and applications. The Agent automatically reads this configuration to resolve host aliases, app names, SSH credentials, and file paths.
Configuration File
The structure of the deploy-apps.json file should be as follows:
CODEBLOCK10
How It Works
When you reference a host alias or app name, the Agent:
- 1. Reads
deploy-apps.json to find the matching configuration - Resolves
host to the actual SSH hostname/IP - Constructs
path from INLINECODE32 - Uses the configured
user for SSH authentication
Configuration Parameters
| Parameter | Type | Required | Description |
|---|
| INLINECODE34 | string | Yes | Remote SSH hostname or IP |
| INLINECODE35 |
string | Yes | Base directory containing app folders |
|
hosts.<alias>.user | string | Yes | SSH username |
|
hosts.<alias>.description | string | No | Human-readable description |
|
hosts.<alias>.apps.<name>.description | string | Yes* | App description |
|
hosts.<alias>.apps.<name>.update-command | string | Yes* | Custom command to execute update |
Path Resolution Example
With:
- -
base-dir: INLINECODE41 - INLINECODE42 : INLINECODE43
The resolved path would be: INLINECODE44
See Also
Docker 远程管理技能
通过SSH连接远程管理Docker Compose实例。
概述
本技能提供了一套完整的操作,用于远程服务器上的Docker Compose生命周期管理。所有操作均通过SSH执行,客户端和服务器端仅需标准SSH和Docker工具。
快速开始
bash
启动服务
docker
composeup host=192.168.1.100 user=root path=/opt/myapp
检查状态
docker
composeps host=192.168.1.100 user=root path=/opt/myapp
查看日志
docker
composelogs host=192.168.1.100 user=root path=/opt/myapp tail=50
更新并重启
docker
composeupdate host=192.168.1.100 user=root path=/opt/myapp pull=always
操作
dockercomposeup
以分离模式启动Docker Compose服务。
参数:
- - host(必填):远程SSH主机(IP或主机名)
- user(必填):SSH用户名
- path(必填):包含docker-compose.yml的目录
- port(可选,默认:22):SSH端口
- key_path(可选):SSH私钥路径
- timeout(可选,默认:60):操作超时时间(秒)
示例:
dockercomposeup host=192.168.1.100 user=admin path=/opt/app port=2222
dockercomposedown
停止并移除docker-compose.yml中定义的容器、网络和卷。
参数: 与up相同
示例:
dockercomposedown host=192.168.1.100 user=admin path=/opt/app
dockercomposestart
启动特定的已停止服务。
参数:
- - 所有up的参数
- service(可选):要启动的服务名称(未指定则启动所有服务)
示例:
dockercomposestart host=192.168.1.100 user=admin path=/opt/app service=web
dockercomposestop
停止运行中的服务但不移除它们。
参数:
- - 所有up的参数
- service(可选):要停止的服务名称(未指定则停止所有服务)
示例:
dockercomposestop host=192.168.1.100 user=admin path=/opt/app service=worker
dockercomposerestart
重启服务。
参数:
- - 所有up的参数
- service(可选):要重启的服务名称
示例:
dockercomposerestart host=192.168.1.100 user=admin path=/opt/app service=api
dockercomposeps
列出所有容器及其状态。
参数: 与up相同
示例:
dockercomposeps host=192.168.1.100 user=admin path=/opt/app
dockercomposelogs
获取并显示服务的日志。
参数:
- - 所有up的参数
- service(可选):过滤特定服务的日志
- tail(可选,默认:100):显示的行数
- follow(可选,默认:false):持续流式输出日志
示例:
dockercomposelogs host=192.168.1.100 user=admin path=/opt/app tail=50 follow=true
dockercomposeupdate
拉取最新镜像并重启服务。
参数:
- - 所有up的参数
- force_recreate(可选,默认:false):强制重新创建容器
- pull(可选):镜像拉取策略(never、always、missing)
- command(可选):自定义命令,替代默认的pull && up
示例:
默认行为
docker
composeupdate host=192.168.1.100 user=admin path=/opt/app pull=always
自定义命令
docker
composeupdate host=192.168.1.100 user=admin path=/opt/app command=sh ./upgrade.sh
dockercomposeexec
在运行中的容器内执行命令。
参数:
- - 所有up的参数
- service(必填):要执行命令的容器名称
- command(必填):要执行的命令
- timeout(可选,默认:60):命令执行超时时间
示例:
dockercomposeexec host=192.168.1.100 user=admin path=/opt/app service=web command=ls -la /app
实现说明
- - SSH连接默认使用基于密钥的身份验证
- 在运行docker compose命令前始终切换到正确的目录
- 启动服务时使用-d标志启用分离模式
- 优雅处理SSH连接超时和身份验证失败
- 返回包含成功/失败状态和相关日志的结构化输出
- 操作失败时包含错误上下文信息
错误处理
常见错误及处理方法:
- 1. SSH连接被拒绝:验证主机、端口和网络访问
- 身份验证失败:检查SSH密钥路径和权限
- 路径未找到:确保指定路径下存在docker-compose.yml
- Docker未运行:验证远程主机上Docker守护进程可访问
- 权限被拒绝:检查用户是否有Docker套接字的访问权限
部署配置
本技能支持deploy-apps.json配置文件,用于映射远程主机和应用程序。Agent会自动读取此配置以解析主机别名、应用名称、SSH凭据和文件路径。
配置文件
deploy-apps.json文件的结构如下:
json
{
hosts: {
<主机别名>: {
host: remote.server.com,
description: 服务器描述,
base-dir: /path/to/docker,
user: ssh-user,
apps: {
<应用名称>: {
description: 应用描述,
update-command: 执行更新的自定义命令
}
}
}
}
}
工作原理
当您引用主机别名或应用名称时,Agent会:
- 1. 读取deploy-apps.json以查找匹配的配置
- 将host解析为实际的SSH主机名/IP
- 从/<应用名称>构建path
- 使用配置的user进行SSH身份验证
配置参数
| 参数 | 类型 | 必填 | 描述 |
|---|
| hosts.<别名>.host | string | 是 | 远程SSH主机名或IP |
| hosts.<别名>.base-dir |
string | 是 | 包含应用文件夹的基础目录 |
| hosts.<别名>.user | string | 是 | SSH用户名 |
| hosts.<别名>.description | string | 否 | 人类可读的描述 |
| hosts.<别名>.apps.<名称>.description | string | 是* | 应用描述 |
| hosts.<别名>.apps.<名称>.update-command | string | 是* | 执行更新的自定义命令 |
路径解析示例
当:
- - base-dir:/data/docker
- app-name:mysql
解析后的路径为:/data/docker/mysql
参见