https://github.com/devcontainer-env/devcontainer-env
A developer CLI that bridges devcontainers and the host environment — run host commands with devcontainer service environments and automatically rewrite container service URLs to host ports.
https://github.com/devcontainer-env/devcontainer-env
devcontainer developer-tools development-environment development-workflow docker docker-compose rust
Last synced: about 1 month ago
JSON representation
A developer CLI that bridges devcontainers and the host environment — run host commands with devcontainer service environments and automatically rewrite container service URLs to host ports.
- Host: GitHub
- URL: https://github.com/devcontainer-env/devcontainer-env
- Owner: devcontainer-env
- License: mit
- Created: 2026-03-12T11:30:36.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2026-04-09T03:12:40.000Z (about 1 month ago)
- Last Synced: 2026-04-09T03:25:55.111Z (about 1 month ago)
- Topics: devcontainer, developer-tools, development-environment, development-workflow, docker, docker-compose, rust
- Language: Rust
- Homepage:
- Size: 61.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# devcontainer-env
> Bridge devcontainers and the host environment — run host commands with devcontainer service environments and automatically rewrite container service URLs to host ports.
[](https://github.com/devcontainer-env/devcontainer-env/actions/workflows/test.yml)
[](https://github.com/devcontainer-env/devcontainer-env/releases/latest)
[](https://crates.io/crates/devcontainer-env)
[](LICENSE)
```bash
eval "$(devcontainer-env export)"
```
## Installation
### Cargo (Crates.io)
```bash
cargo install devcontainer-env
```
### Nix (recommended)
Run directly without installing:
```bash
nix run github:devcontainer-env/devcontainer-env -- exec -- your-command
```
Or install into your profile:
```bash
nix profile install github:devcontainer-env/devcontainer-env
```
## Usage
```
Usage: devcontainer-env
Commands:
inspect Inspect and display the devcontainer environment configuration and service port mappings.
export Export devcontainer service environment variables with container URLs rewritten to host ports.
exec Execute a host command with the devcontainer service environment applied, rewriting container URLs to host ports.
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
-V, --version Print version
```
**devcontainer-env export** — Output environment variables from `containerEnv` as shell statements.
Only variables defined in the `containerEnv` section are exported to the host (not service configuration or service environment variables). See [Configuration](#configuration) for an example.
```bash
$ devcontainer-env export
```
```bash
export EXAMPLE_API_DATABASE_URL=postgres://vscode@127.0.0.1:32771/example-db?sslmode=disable
```
**devcontainer-env exec** — Run a command with devcontainer environment available:
```bash
devcontainer-env exec -- [ARGS...]
```
The `--` separator is required. Everything after `--` is passed to the command.
**devcontainer-env inspect** — Parse and display the devcontainer configuration:
```bash
$ devcontainer-env inspect
```
```bash
Workspace: /Users/iamralch/Projects/github.com/devcontainer-env/devcontainer-env/example
Containers:
example_devcontainer-postgres-1
Image: postgres:18-bookworm
Hosts: example_devcontainer-postgres-1, postgres, 3dac21f544da
Ports: 5432 → 0.0.0.0:32771, 5432 → :::32771
example_devcontainer-workspace-1, main
Image: mcr.microsoft.com/devcontainers/base:noble
Hosts: example_devcontainer-workspace-1, workspace, 742062d03e2e
Environment:
EXAMPLE_API_DATABASE_URL = postgres://vscode@127.0.0.1:32771/example-db?sslmode=disable
```
## Configuration
See the [`example/`](./example) directory for a complete working configuration.
### Variable Exporting
DevContainer supports two ways to define environment variables: `containerEnv` and `remoteEnv`. **`devcontainer-env` works exclusively with `containerEnv`.** Variables in `containerEnv` are set when the container starts and apply to all processes. Variables in `remoteEnv` are set specifically for the VS Code server process and its sub-processes (terminals, tasks) — they can be updated without rebuilding the container but do not apply to background daemons. Use `containerEnv` for any variables you want accessible on the host (connection strings, API endpoints, service URLs).
### Port Mapping
Use `ports: []` syntax (not `"HOST:PORT"`) to let Docker assign random available host ports. This prevents conflicts when running multiple devcontainers or projects simultaneously. `devcontainer-env export` automatically detects the Docker-assigned host port and makes it available in exported environment variables. Do not use `forwardPorts` in `devcontainer.json` — rely on `docker-compose.yml` port mapping instead.
## License
[MIT](LICENSE) — Copyright (c) 2025 devcontainer-env