--- id: Docker-Attach-mode title: "Docker Attach模式" type: concept tags: [docker, development, remote] sources: [] last_updated: 2026-04-15 --- ## Definition Docker Attach 模式是一种远程开发方式:Trae/VS Code 直接"进入"已在服务器运行的 Docker 容器,在容器内部启动编辑器后端,实现完全隔离的开发环境。 ## vs 宿主机编辑模式 | 维度 | Attach 模式 | 宿主机编辑模式 | |------|------------|-------------| | 编辑器位置 | 容器内 | 宿主机(Ubuntu) | | 环境 | 容器定义的环境 | 宿主机环境 | | Git 凭证 | 需 SSH Agent 转发 | 自动复用宿主机配置 | | 文件权限 | 容器内生成文件属 root | 正常 | | 适合场景 | 深度定制化环境 | docker-compose 管理 | ## Workflow (Trae) 1. Remote SSH 连接到 Ubuntu 服务器 2. Docker 插件中找到目标容器 3. 右键 → "Attach Visual Studio Code" 4. Trae 在容器内安装 Trae Server ## Related Concepts - [[Remote SSH]]:Attach 模式的前置条件 - [[Bind Mount]]:容器内文件与宿主机共享的挂载机制 - [[Docker Compose]]:定义开发环境容器的配置文件