{"id":20565006,"url":"https://github.com/nohzafk/devcontainer-cli-port-forwarder","last_synced_at":"2025-04-14T15:14:06.459Z","repository":{"id":217684403,"uuid":"744552260","full_name":"nohzafk/devcontainer-cli-port-forwarder","owner":"nohzafk","description":"Enable Port Forwarding when using DevContainer CLI","archived":false,"fork":false,"pushed_at":"2024-06-08T17:47:01.000Z","size":13,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-14T15:13:55.297Z","etag":null,"topics":["devcontainer","devcontainer-development","devcontainers"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nohzafk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-17T14:33:45.000Z","updated_at":"2024-09-03T08:15:17.000Z","dependencies_parsed_at":"2024-01-17T22:59:14.005Z","dependency_job_id":"c1fcf4bb-fca0-4f1c-b2a2-1bc7b5b1b667","html_url":"https://github.com/nohzafk/devcontainer-cli-port-forwarder","commit_stats":null,"previous_names":["nohzafk/devcontainer-cli-port-forwarder"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nohzafk%2Fdevcontainer-cli-port-forwarder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nohzafk%2Fdevcontainer-cli-port-forwarder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nohzafk%2Fdevcontainer-cli-port-forwarder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nohzafk%2Fdevcontainer-cli-port-forwarder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nohzafk","download_url":"https://codeload.github.com/nohzafk/devcontainer-cli-port-forwarder/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248904637,"owners_count":21180835,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["devcontainer","devcontainer-development","devcontainers"],"created_at":"2024-11-16T04:30:18.754Z","updated_at":"2025-04-14T15:14:06.435Z","avatar_url":"https://github.com/nohzafk.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DevContainer CLI Port Forwarder\n\n# Overview\nThis Python script dynamically forward ports from a host machine to a Docker container according to `devcontainer.json` **forwardPorts**.\n\nThis Python script is created because currently DevContainer CLI does not support port forwarding, see [devcontainers/cli issue](https://github.com/devcontainers/cli/issues/22)\n\n## Usage Context\n- This script is only needed if you are managing your containers directly with the **devcontainer CLI**.\n- If you are using vSCode with the Visual Studio Code Dev Containers extension,The VS Code extension already includes built-in support for port forwarding you do not need to use this script.\n\n## Prerequisites\n- host machine: Python 3 interpreter is installed.\n- container: `socat` is installed.\n\n\n\n## Features\n- Dynamic Port Forwarding: Automates the process of forwarding specified ports from the host to a Docker container.\n- Automatic Shutdown: The script automatically exits when the associated Docker container stops running.\n\n# Installation\ngit clone this project under your project's `.devcontainer` directory, or anywhere you like.\n\n```shell\ngit clone https://github.com/nohzafk/devcontainer-cli-port-forwarder.git .devcontainer/devcontainer-cli-port-forwarder\n```\n\nThis script won't automatically install `socat` inside the container for you, you need to install `socat` inside the container.\n\nyou can simply add a line in **onCreateCommand** in your `devcontainer.json`\n\n```json\n\"onCreateCommand\": \"sudo apt update \u0026\u0026 sudo apt install -y socat\",\n```\n\nor use nix feature\n```json\n\"features\": {\n    \"ghcr.io/devcontainers/features/nix:1\": {\n        \"packages\": \"socat\"\n    }\n},\n```\n\n# Usage\nIn your **devcontainer.json**, set the `initializeCommand` to run the script in the background when the container is being initialized:\n\n```json\n\"initializeCommand\": \"python3 .devcontainer/devcontainer-cli-port-forwarder/forwarder.py \u0026\",\n```\n\nTo enable verbose output, which provides more detailed information about the port forwarding process, modify the initializeCommand as follows:\n```json\n\"initializeCommand\": \"python3 .devcontainer/devcontainer-cli-port-forwarder/forwarder.py verbose \u0026\",\n```\n\nand finally specify the ports that you want to forward from host by **forwardPorts**,\n\nfor example port 2222 used by devcontainer feature sshd `\"ghcr.io/devcontainers/features/sshd:1\": {},`\n\nUse 'forwardPorts' to make a list of ports inside the container available locally.\n```json\n\"forwardPorts\": [2222],\n```\n\nOnce configured in your devcontainer.json, the script will automatically start when you create a devcontainer using the devcontainer CLI. It listens on specified ports and forwards them to the Docker container.\n\n- The script runs in the background and does not require manual intervention once started.\n- When the Docker container stops, the script detects this and exits automatically, ensuring that resources are not left unnecessarily consumed on the host machine.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnohzafk%2Fdevcontainer-cli-port-forwarder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnohzafk%2Fdevcontainer-cli-port-forwarder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnohzafk%2Fdevcontainer-cli-port-forwarder/lists"}