Giter VIP home page Giter VIP logo

docker-host's Introduction

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

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

nc 5353 -lk -u -w0

Docker Link

Run the dockerhost container.

docker run --rm \
  --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"]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.