# VSCode Remote-Containers 插件使用说明 The Visual Studio Code Remote - Containers extension lets you use a Docker container as a full-featured development environment. It allows you to open any folder inside (or mounted into) a container and take advantage of Visual Studio Code's full feature set. A devcontainer.json file in your project tells VS Code how to access (or create) a development container with a well-defined tool and runtime stack. This container can be used to run an application or to separate tools, libraries, or runtimes needed for working with a codebase. Workspace files are mounted from the local file system or copied or cloned into the container. Extensions are installed and run inside the container, where they have full access to the tools, platform, and file system. This means that you can seamlessly switch your entire development environment just by connecting to a different container. ```mermaid flowchart LR classDef ClassM fill:#e96; subgraph Local OS subgraph VS [VS Code] Theme0[Theme/UI Extension] Theme1[Theme/UI Extension] end SrcReal[(Source Code)] end subgraph Container subgraph VServer [VS Code VServer] Work0[Workspace Extension] Work1[Workspace Extension] end SrcMirr[(Source Code)]:::ClassM FileSys[(File System)] Term[Terminal Process] App[Running Application] Dbg[Debugger] end VS -->|Exposed Port| VServer SrcReal -->|Volume Mount| SrcMirr VServer --> SrcMirr VServer --> FileSys VServer --> Term VServer --> App VServer --> Dbg ``` This lets VS Code provide a local-quality development experience — including full IntelliSense (completions), code navigation, and debugging — regardless of where your tools (or code) are located. ## 1.System requirements **Local:** * Windows: Docker Desktop 2.0+ on Windows 10 Pro/Enterprise. Windows 10 Home (2004+) requires Docker Desktop 2.3+ and the WSL 2 back-end. (Docker Toolbox is not supported. Windows container images are not supported.) * macOS: Docker Desktop 2.0+. * Linux: Docker CE/EE 18.06+ and Docker Compose 1.21+. (The Ubuntu snap package is not supported.) **Containers:** * x86_64 / ARMv7l (AArch32) / ARMv8l (AArch64) Debian 9+, Ubuntu 16.04+, CentOS / RHEL 7+ * x86_64 Alpine Linux 3.9+ Other glibc based Linux containers may work if they have needed Linux prerequisites. ## 2.基本使用方法 Ctrl+P,输入 Remote-Containers 可执行对应命令。 ### 2.1.Attach to Running Container 该命令可以连接到一个正在运行的容器上(通过 Docker pull 然后 start 的容器)。 ### 2.2.devcontainer.json 该文件可以帮助快速创建/运行容器: 于工程目录下创建 .devcontainer/devcontainer.json 文件。按如下内容编写: ```json { "image": "ubuntu:18.04", "forwardPorts": [3000] } ``` 然后使用命令:Reopen in Container 可从本地 ubuntu:18.04 image 文件创建容器(如果已存在对应该 Workspace 的容器则直接运行)。 ### 2.3.Close Remote Connection 如果已经连接到容器,可通过 File 菜单中的 Close Remote Connection 命令关闭连接。关闭连接后自动运行的容器将退出运行,Attach 的容器则不受影响。 ## 3.官方帮助文档 * [Developing inside a Container](https://code.visualstudio.com/docs/remote/containers) * [Create a development container](https://code.visualstudio.com/docs/remote/create-dev-container) * [Remote development in Containers](https://code.visualstudio.com/docs/remote/containers-tutorial)