{"id":13419834,"url":"https://github.com/qoomon/docker-host","last_synced_at":"2025-05-14T18:06:17.089Z","repository":{"id":26216354,"uuid":"107676899","full_name":"qoomon/docker-host","owner":"qoomon","description":"A docker sidecar container to forward all traffic to local docker host or any other host","archived":false,"fork":false,"pushed_at":"2025-03-25T07:52:14.000Z","size":163,"stargazers_count":1130,"open_issues_count":1,"forks_count":89,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-04-13T13:16:46.703Z","etag":null,"topics":["access","connection","docker","docker-compose","dockerhost","egress","firewall","host","internal","iptables","linux","localhost","macos","nat","nftables","polyfill","port-forwarding","sidecar","tunnel"],"latest_commit_sha":null,"homepage":"","language":"Shell","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/qoomon.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,"zenodo":null}},"created_at":"2017-10-20T12:44:11.000Z","updated_at":"2025-04-10T10:00:57.000Z","dependencies_parsed_at":"2023-11-10T14:26:49.008Z","dependency_job_id":"f48eb35b-63ec-4ba4-bf89-ecbea9317ad7","html_url":"https://github.com/qoomon/docker-host","commit_stats":{"total_commits":181,"total_committers":21,"mean_commits":8.619047619047619,"dds":"0.17679558011049723","last_synced_commit":"23f8f9f522ce74e338844013c070dda827920cf3"},"previous_names":[],"tags_count":41,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qoomon%2Fdocker-host","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qoomon%2Fdocker-host/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qoomon%2Fdocker-host/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qoomon%2Fdocker-host/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qoomon","download_url":"https://codeload.github.com/qoomon/docker-host/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254198514,"owners_count":22030965,"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":["access","connection","docker","docker-compose","dockerhost","egress","firewall","host","internal","iptables","linux","localhost","macos","nat","nftables","polyfill","port-forwarding","sidecar","tunnel"],"created_at":"2024-07-30T22:01:21.630Z","updated_at":"2025-05-14T18:06:12.071Z","avatar_url":"https://github.com/qoomon.png","language":"Shell","readme":"\n# docker-host [![starline](https://starlines.qoo.monster/assets/qoomon/docker-host)](https://github.com/qoomon/starlines)\n\n[![GitHub release](https://img.shields.io/github/release/qoomon/docker-host.svg)](https://hub.docker.com/r/qoomon/docker-host/)\n[![Docker Stars](https://img.shields.io/docker/pulls/qoomon/docker-host.svg)](https://hub.docker.com/r/qoomon/docker-host/)\n[![Build Workflow](https://github.com/qoomon/docker-host/workflows/Build/badge.svg)](https://github.com/qoomon/docker-host/actions?query=workflow%3ABuild)\n\n\nDocker Image Tags:\n* `latest`\n* `3`\n* `3.x.x`\n\nDocker image to forward **TCP** and **UDP** traffic to the docker host. This\nalso works for (rootless) podman. This README.md uses the term docker, but you\ncan read that as both `docker` and `podman` (it works for both), unless\notherwise specified.\n\nThis container will determine the docker host address in the following order\n* If set use environment variable `DOCKER_HOST`. Can be an IP address or a DNS name.\n  * This allows you to use this image to forward traffic to arbitrary destinations, not only the docker host.\n* Try to resolve host address from DNS names.\n  * docker hostname `host.docker.internal` \n  * podman hostname `host.containers.internal`\n* Defaults to default gateway (`ip -4 route show default`)\n\n#### Ports\nBy default all ports (`1-65535`) are forwarded to docker host. \n\n* You may restrict ports by setting environment variable `PORTS` to a space and/or comma separated list of ports and/or port ranges e.g \n  * `docker run -e PORTS='443, 8000-9000' ...`. \n* You may also configure port mapping e.g. `443:8443, 8000-9000:5000-6000` (`CONTAINER_PORT:HOST_PORT`).\n\n---\n\u003e [!IMPORTANT]\n\u003e #### On **Linux systems**\n\u003e \n\u003e * You have to bind your host applications to `0.0.0.0` or `bridge` network gateway in addition to `127.0.0.1`. \n\u003e \n\u003e   Use following docker command to get the bridge network gateway IP address \n\u003e \n\u003e   `docker network inspect bridge --format='{{( index .IPAM.Config 0).Gateway}}'`\n\u003e \n\u003e   \u003e For (rootless) **podman**, it's sufficient to bind to localhost, assuming\n\u003e   \u003e default podman installation.\n\u003e \n\u003e * You might need to configure your firewall of the host system to allow the docker-host container to communicate with the host on your relevant port, see [#21](https://github.com/qoomon/docker-host/issues/21#issuecomment-497831038).\n\u003e \n\u003e #### On **MacOS systems**\n\u003e \n\u003e ##### Podman Only\n\u003e \n\u003e * You probably need to add `nf_nat` kernal module to podman machine by running following commands\n\u003e \n\u003e   ```shell\n\u003e   podman machine ssh\n\u003e \n\u003e   sudo modprobe nf_nat\n\u003e   ```\n\n---\n\n# Examples\nThese examples will send messages from docker container to docker host with `netcat`\n\n### Preparation\nStart `netcat` server **TCP** on port `2323` to receive and display messages\n```sh\nnc -lk 2323\n```\nStart `netcat` server **UDP** on port `5353` to receive and display messages\n```sh\nnc -lk 5353 -u\n```   \n\n## Docker Link\nRun the dockerhost container.\n```sh\ndocker run \\\n  --name 'docker-host' \\\n  --cap-add=NET_ADMIN --cap-add=NET_RAW \\\n  --restart on-failure \\\n  -d qoomon/docker-host\n```\nRun your application container and link the dockerhost container.\nThe dockerhost will be reachable through the domain/link `dockerhost` of the dockerhost container\n#### This example will let you send messages to **TCP** `netcat` server on docker host.\n```sh\ndocker run --rm \\\n  --link 'docker-host' \\\n  -it alpine nc 'docker-host' 2323 -v\n```\n#### This example will let you send messages to **UDP** `netcat` server on docker host.\n```sh\ndocker run --rm \\\n  --link 'docker-host' \\\n  -it alpine nc 'docker-host' 5353 -u -v\n```\n\n## Docker Network\nCreate the dockerhost network.\n```sh\nnetwork_name=\"Network-$RANDOM\"\ndocker network create \"$network_name\"\n```\nRun the dockerhost container within the dockerhost network.\n```sh\ndocker run --name \"${network_name}-docker-host\" \\\n  --cap-add=NET_ADMIN --cap-add=NET_RAW \\\n  --restart on-failure \\\n  --net=${network_name} --network-alias 'docker-host' \\\n  qoomon/docker-host\n```\nRun your application container within the dockerhost network.\nThe dockerhost will be reachable through the domain/link `docker-host` of the dockerhost container\n#### This example will let you send messages to **TCP** `netcat` server on docker host.\n```sh\ndocker run --rm \\\n  --link 'docker-host' \\\n  -it alpine nc 'docker-host' 2323 -v\n```\n#### This example will let you send messages to **UDP** `netcat` server on docker host.\n```sh\ndocker run --rm \\\n  --link 'docker-host' \\\n  -it alpine nc 'docker-host' 5353 -u -v\n```\n\n## Docker Compose\n```yaml\nversion: '2'\n\nservices:\n    docker-host:\n        image: qoomon/docker-host\n        cap_add: [ 'NET_ADMIN', 'NET_RAW' ]\n        mem_limit: 8M\n        restart: on-failure\n    tcp_message_emitter:\n        depends_on: [ docker-host ]\n        image: alpine\n        command: [ \"sh\", \"-c\", \"while :; do date; sleep 1; done | nc 'docker-host' 2323 -v\"]\n    udp_message_emitter:\n        depends_on: [ docker-host ]\n        image: alpine\n        command: [ \"sh\", \"-c\", \"while :; do date; sleep 1; done | nc 'docker-host' 5353 -u -v\"]\n```\n\n---\n# External References\n* https://medium.com/@sam_ngu/connecting-to-docker-host-mysql-from-docker-container-linux-ubuntu-766e526542fd\n","funding_links":[],"categories":["Shell","docker","macos"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqoomon%2Fdocker-host","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqoomon%2Fdocker-host","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqoomon%2Fdocker-host/lists"}