Files
nexus/wiki/concepts/Attach容器.md
2026-04-22 12:02:55 +08:00

36 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "Attach 容器"
type: concept
tags: [docker, remote-development, debugging]
last_updated: 2026-04-22
---
## Definition
将 IDE 直接连接到正在运行的 Docker 容器内部进行代码开发和调试的工作模式。
## Mechanism
1. 在已运行的 Docker 容器中安装 IDE Server 代理
2. 本地 IDE UI 通过 SSH/TCP 隧道与容器内 IDE Server 通信
3. 所有代码编辑、终端、插件均运行在容器内部
4. 容器重启后需重新 Attach
## Characteristics
- **环境完全隔离**:直接使用容器内的 Python/Node/Go 等语言环境,无需在宿主机安装
- **适合调试**:数据库、服务等依赖已在容器中运行
- **适合轻量级修改**:代码变更即时生效(取决于是否使用 Bind Mount
- **不适合镜像重建场景**:如需重新 build Dockerfile需退出 Attach 重建
## vs 宿主机文件模式
| 维度 | Attach 容器 | 宿主机文件 + Docker CLI |
|------|-------------|------------------------|
| 代码位置 | 容器内部 | 宿主机文件系统 |
| 环境隔离 | ✅ 完全 | ⚠️ 依赖宿主机环境 |
| 适合场景 | 调试、多语言混合 | docker-compose 编排 |
| Git 操作 | 需 SSH Agent Forwarding | 直接使用 |
## Connections
- [[Remote-SSH]] — Attach 的实现基础
- [[Bind Mount]] — 如需代码实时生效,可结合使用
- [[Docker]] — 容器平台
- [[Trae]] — 支持 Attach 容器的 IDE