Skip to content

Commit 00177b2

Browse files
Add experimental Dev Container support to Positron (#10884)
This change adds early, experimental support for Dev Containers to Positron. <img width="1226" height="860" alt="image" src="https://github.com/user-attachments/assets/e0ca3360-12c9-47da-93c6-cade37db47a4" /> Because the feature is experimental, it is currently behind a feature flag: <img width="578" height="136" alt="image" src="https://github.com/user-attachments/assets/fd2495e9-dc88-436a-a0c7-035bf75623fa" /> The goal of this change is to enable the most common dev container workflows that center around building (or rebuilding) a container and opening the workspace inside the container. However, note that in this early version, many features are not implemented or are incomplete. Specifically: - musl-based Linux distributions (such as Alpine) are not supported (#10468); the container must be running a version of Linux already supported by Positron - Only single-container configurations are supported (no `docker compose`) - No tools or templates are supplied for creating or authoring `devcontainer.json` files - Only one container is supported per project - Docker volumes are not supported, just regular mounts - In the MRU, dev containers show up with the remote rather than local path (e.g. `/workspaces/foo`) - Container management features (see/attach to running containers) are not available when inside a container For compatibility, the new extension uses largely the same command names and settings as the official VS Code Dev Containers extension. It also includes a lightly modified version of the [Dev Containers CLI](https://github.com/devcontainers/cli) reference implementation. The implementation is used to derive the correct container management commands, which are (generally) executed in Positron terminals for visibility. Addresses #4691. ### Release Notes <!-- Optionally, replace `N/A` with text to be included in the next release notes. The `N/A` bullets are ignored. If you refer to one or more Positron issues, these issues are used to collect information about the feature or bugfix, such as the relevant language pack as determined by Github labels of type `lang: `. The note will automatically be tagged with the language. These notes are typically filled by the Positron team. If you are an external contributor, you may ignore this section. --> #### New Features - Experimental support for Dev Containers (#4691) #### Bug Fixes - N/A ### QA Notes Like Remote SSH, this feature is difficult to test outside release builds since it needs to download a matching server component into the container. And -- also like remote SSH -- there's a setting to change the download URL. If you need to test a build that doesn't have a released Positron version to download, you can change this setting to the URL of the closest matching build. This feature should be tested across all three operating systems since the Docker integration is somewhat OS-specific. --------- Co-authored-by: positron-bot[bot] <173392469+positron-bot[bot]@users.noreply.github.com>
1 parent 28310d2 commit 00177b2

File tree

113 files changed

+26645
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+26645
-0
lines changed

build/gulpfile.extensions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const compilations = [
3434
'extensions/positron-catalog-explorer/tsconfig.json',
3535
'extensions/positron-code-cells/tsconfig.json',
3636
'extensions/positron-connections/tsconfig.json',
37+
'extensions/positron-dev-containers/tsconfig.json',
3738
'extensions/positron-duckdb/tsconfig.json',
3839
'extensions/positron-environment/tsconfig.json',
3940
'extensions/positron-ipywidgets/renderer/tsconfig.json',

build/npm/dirs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const dirs = [
1717
'extensions/positron-code-cells',
1818
'extensions/positron-copilot-chat',
1919
'extensions/positron-connections',
20+
'extensions/positron-dev-containers',
2021
'extensions/positron-duckdb',
2122
'extensions/positron-environment',
2223
'extensions/positron-ipywidgets',
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Dev Containers Extension for Positron
2+
3+
## Overview
4+
5+
The Dev Containers extension enables you to open any folder or repository inside a Docker container and take advantage of Positron's full feature set within that containerized environment. This allows you to define your project's dependencies declaratively, install them in a lightweight container, and run the entire project inside the container with a consistent, reproducible development environment.
6+
7+
For compatibility with VS Code, this extension uses most of the same command IDs and setting names from VS Code's version of the extension. The extension itself is novel code, with the exception of the contents of the `spec` folder, which is adapted from the MIT-licensed [dev container reference implementation](https://github.com/devcontainers/cli).
8+
9+
## Requirements
10+
11+
- Docker or Podman installed and running
12+
- A workspace with a `.devcontainer.json` or `.devcontainer/devcontainer.json` file
13+
14+
## Configuration
15+
16+
Enable the extension in your settings:
17+
18+
```json
19+
{
20+
"dev.containers.enable": true
21+
}
22+
```
23+
24+
## Usage
25+
26+
### Opening a Folder in a Container
27+
28+
1. Open a folder that contains a `.devcontainer.json` file
29+
2. Click the notification prompt, or
30+
3. Use the command palette: **Dev Containers: Reopen in Container**
31+
32+
### Attaching to a Running Container
33+
34+
1. Open the Remote Explorer view
35+
2. Expand the "Dev Containers" section
36+
3. Right-click a running container and select "Attach in Current Window" or "Attach in New Window"
37+
38+
### Rebuilding a Container
39+
40+
When you've made changes to your `devcontainer.json` or `Dockerfile`:
41+
42+
- **Dev Containers: Rebuild Container** - Rebuild using cache
43+
- **Dev Containers: Rebuild Without Cache** - Full rebuild from scratch
44+
- **Dev Containers: Rebuild and Reopen in Container** - Rebuild and automatically reopen
45+
46+
### Key Components
47+
48+
#### Extension Entry Point (`extension.ts`)
49+
- Activates the extension when enabled
50+
- Registers commands, views, and authority resolvers
51+
- Initializes core managers and services
52+
- Handles pending rebuild requests
53+
54+
#### Remote Authority Resolver (`remote/authorityResolver.ts`)
55+
- Resolves `dev-container://` and `attached-container://` URIs
56+
- Manages connections to containers
57+
- Handles workspace folder resolution
58+
- Implements VS Code's remote development protocol
59+
60+
#### Connection Manager (`remote/connectionManager.ts`)
61+
- Manages active connections to containers
62+
- Tracks connection state and lifecycle
63+
- Handles connection failures and recovery
64+
- Coordinates with port forwarding
65+
66+
#### Dev Container Manager (`container/devContainerManager.ts`)
67+
- Creates and starts containers from `devcontainer.json`
68+
- Handles container building and rebuilding
69+
- Manages container lifecycle (start, stop, remove)
70+
- Retrieves container information and logs
71+
72+
#### Server Installer (`server/serverInstaller.ts`)
73+
- Downloads the Positron server for the container platform
74+
- Installs and configures the server inside containers
75+
- Generates connection tokens for secure communication
76+
- Handles server updates and versioning
77+
78+
#### Workspace Mapping Storage (`common/workspaceMappingStorage.ts`)
79+
- Persists mappings between container IDs and workspace paths
80+
- Enables proper workspace resolution across window reloads
81+
- Provides cleanup for stale mappings
82+
83+
#### Dev Container Reference CLI (spec/)
84+
- Copy of the Microsoft Dev Container Reference CLI
85+
- Used to manage containers and form Docker commands
86+
87+
### Remote Development Flow
88+
89+
The workflow typically looks like this;
90+
91+
1. User invokes "Reopen in Container"
92+
2. Extension reads `devcontainer.json` and creates/starts container
93+
3. Positron server is downloaded and installed in container
94+
4. VS Code resolves the remote authority and establishes connection
95+
5. Extension maps local paths to container paths
96+
6. Necessary ports are forwarded from container to host
97+
7. User can now work with code inside the container
98+
99+
## Known Limitations
100+
101+
- Requires glibc-based Linux since Positron Server builds of Linux require glibc (e.g. Alpine will not work)
102+
- Doesn't support "Create from template"; you need to create Dockerfiles / devcontainer JSON files by hand
103+
- Doesn't support development volumes (popular feature from VS Code's implementation, used for e.g. faster I/O)
104+
- Container management views and features are not available if you are inside a container/remote
105+
- Currently experimental and requires explicit enablement
106+
- Requires Docker or Podman to be installed and running
107+
- GPU support is platform-dependent
108+
- Some features have limited support in containers
109+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (C) 2025 Posit Software, PBC. All rights reserved.
3+
* Licensed under the Elastic License 2.0. See LICENSE.txt for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
//@ts-check
7+
8+
'use strict';
9+
10+
const withDefaults = require('../shared.webpack.config.mjs').default;
11+
12+
module.exports.default = withDefaults({
13+
context: __dirname,
14+
entry: {
15+
extension: './src/extension.ts',
16+
}
17+
});

0 commit comments

Comments
 (0)