devcontainer-env
Bridge devcontainers and the host environment — run host commands with devcontainer service environments and automatically rewrite container service URLs to host ports.

Installation
Cargo (Crates.io)
Nix (recommended)
Run directly without installing:
Or install into your profile:
Usage
Usage: devcontainer-env <COMMAND>
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 for an example.
devcontainer-env exec — Run a command with devcontainer environment available:
The -- separator is required. Everything after -- is passed to the command.
devcontainer-env inspect — Parse and display the devcontainer configuration:
Configuration
See the 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: [<PORT>] 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 — Copyright (c) 2025 devcontainer-env