MIT License

项目介绍

qoomon/docker-host 是一个托管在 GitHub 上的开源项目,主要使用 Shell 编写,采用 MIT License 许可证,目前获得 1.2k 个 Star、85 次 Fork。

仓库全名
qoomon/docker-host
开源许可证
MIT License
Star 数
1.2k
Fork 数
85

README 摘要

Docker Image Tags: latest 3 3.x.x Docker image to forward TCP and UDP traffic to the docker host. This also works for (rootless) podman. This README.md uses the term docker, but you can read that as both docker and podman (it works for both), unless otherwise specified. This container will determine the docker host address in the following order If set use environment variable DOCKERHOST. Can be an IP address or a…

完整内容见 GitHub 原始 README 或本页 。

常见问题

docker-host 用什么语言开发?

主要使用 Shell 编写,采用 MIT License 许可证,目前有 1.2k 个 Star。

docker-host 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 docker-host 的源码?

可以直接克隆仓库:git clone https://github.com/qoomon/docker-host.git,默认分支为 master;安装与运行步骤见仓库 README。

docker-host 最近还在维护吗?

仓库最近一次更新为 1 周前,当前没有未关闭的 Issue;Star 数为 1.2k,可作为社区活跃度的参考。

README

docker-host starline

GitHub release Docker Stars Build Workflow

Docker Image Tags:

  • latest
  • 3
  • 3.x.x

Docker image to forward TCP and UDP traffic to the docker host. This also works for (rootless) podman. This README.md uses the term docker, but you can read that as both docker and podman (it works for both), unless otherwise specified.

This container will determine the docker host address in the following order

  • If set use environment variable DOCKER_HOST. Can be an IP address or a DNS name.
    • This allows you to use this image to forward traffic to arbitrary destinations, not only the docker host.
  • Try to resolve host address from DNS names.
    • docker hostname host.docker.internal
    • podman hostname host.containers.internal
  • Defaults to default gateway (ip -4 route show default)
Ports

By default all ports (1-65535) are forwarded to docker host.

  • 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
    • docker run -e PORTS='443, 8000-9000' ....
  • You may also configure port mapping e.g. 443:8443, 8000-9000:5000-6000 (CONTAINER_PORT:HOST_PORT).

Important 重要
On Linux systems
  • You have to bind your host applications to 0.0.0.0 or bridge network gateway in addition to 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}}'

    For (rootless) podman, it’s sufficient to bind to localhost, assuming default podman installation.

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

  • On MacOS systems
    Podman Only
    • You probably need to add nf_nat kernal module to podman machine by running following commands

      podman machine ssh
      
      sudo modprobe nf_nat
      

    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 -lk 2323
    

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

    nc -lk 5353 -u
    

    Run the dockerhost container.

    docker run \
      --name 'docker-host' \
      --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 'docker-host' \
      -it alpine nc 'docker-host' 2323 -v
    
    This example will let you send messages to UDP netcat server on docker host.
    docker run --rm \
      --link 'docker-host' \
      -it alpine nc 'docker-host' 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}-docker-host" \
      --cap-add=NET_ADMIN --cap-add=NET_RAW \
      --restart on-failure \
      --net=${network_name} --network-alias 'docker-host' \
      qoomon/docker-host
    

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

    This example will let you send messages to TCP netcat server on docker host.
    docker run --rm \
      --link 'docker-host' \
      -it alpine nc 'docker-host' 2323 -v
    
    This example will let you send messages to UDP netcat server on docker host.
    docker run --rm \
      --link 'docker-host' \
      -it alpine nc 'docker-host' 5353 -u -v
    

    Docker Compose

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

    External References

    评论

    暂无评论