docker-host

docker container to forward all traffic to the docker host

Github星跟踪图

docker-host

Build Status

GitHub release

Docker Stars

Docker image to forward TCP and UDP traffic to the docker host.

This container will determine docker host address in the following order

  • Use ip from environment variable DOCKER_HOST if set
    • This allows you to use this image to forward traffic to arbitrary destinations, not only the docker host.
  • Try to resolve host.docker.internal (getent ahostsv4 host.docker.internal)
  • Defaults to default gateway (ip -4 route show default)

⚠️ On Linux systems

  • You have to bind your host applications to bridge network gateway in addition to localhost(127.0.0.1).

    Use following docker command to get the bridge network gateway IP address

    docker network inspect bridge --format='{{( index .IPAM.Config 0).Gateway}}'

  • 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.


Examples

These examples will send messages from docker container to docker host with netcat

Preparation

Start netcat server TCP on port 2323 to receive and display messages

nc 127.0.0.1 2323 -lk

Start netcat server UDP on port 5353 to receive and display messages

nc 127.0.0.1 5353 -lk -u -w0

Run the dockerhost container.

docker run --name 'dockerhost' \
  --cap-add=NET_ADMIN --cap-add=NET_RAW \
  --restart on-failure \
  -d qoomon/docker-host

Run your application container and link the dockerhost container.
The dockerhost will be reachable through the domain/link dockerhost of the dockerhost container

This example will let you send messages to TCP netcat server on docker host.

docker run --rm \
  --link 'dockerhost' \
  -it alpine nc 'dockerhost' 2323 -v

This example will let you send messages to UDP netcat server on docker host.

docker run --rm \
  --link 'dockerhost' \
  -it alpine nc 'dockerhost' 5353 -u -v

Docker Network

Create the dockerhost network.

network_name="Network-$RANDOM"
docker network create "$network_name"

Run the dockerhost container within the dockerhost network.

docker run --name "${network_name}-dockerhost" \
  --cap-add=NET_ADMIN --cap-add=NET_RAW \
  --restart on-failure \
  --net=${network_name} --network-alias 'dockerhost' \
  qoomon/docker-host

Run your application container within the dockerhost network.
The dockerhost will be reachable through the domain/link dockerhost of the dockerhost container

This example will let you send messages to TCP netcat server on docker host.

docker run --rm \
  --link 'dockerhost' \
  -it alpine nc 'dockerhost' 2323 -v

This example will let you send messages to UDP netcat server on docker host.

docker run --rm \
  --link 'dockerhost' \
  -it alpine nc 'dockerhost' 5353 -u -v

Docker Compose

version: '2'

services:
    dockerhost:
        image: qoomon/docker-host
        cap_add: [ 'NET_ADMIN', 'NET_RAW' ]
        mem_limit: 8M
        restart: on-failure
    tcp_message_emitter:
        depends_on: [ dockerhost ]
        image: alpine
        command: [ "sh", "-c", "while :; do date; sleep 1; done, nc 'dockerhost' 2323 -v"]
    udp_message_emitter:
        depends_on: [ dockerhost ]
        image: alpine
        command: [ "sh", "-c", "while :; do date; sleep 1; done, nc 'dockerhost' 5353 -u -v"]

主要指标

概览
名称与所有者qoomon/docker-host
主编程语言Shell
编程语言Shell (语言数: 2)
平台
许可证MIT License
所有者活动
创建于2017-10-20 12:44:11
推送于2025-06-03 19:09:45
最后一次提交2025-06-03 12:04:20
发布数42
最新版本名称v3.3.2 (发布于 )
第一版名称v1.0.0 (发布于 2017-10-24 17:16:54)
用户参与
星数1.1k
关注者数20
派生数89
提交数201
已启用问题?
问题数38
打开的问题数1
拉请求数27
打开的拉请求数0
关闭的拉请求数7
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?