Docker image to forward TCP and UDP traffic to the docker host
- uses dns entry
host.docker.internalif available - or default gateway as docker host
You can manually override the destination IP address by setting the environment variable DOCKER_HOST.
This allows you to use this image to forward traffic to arbitrary destinations, not only the docker host.
bridge network gateway in addition to localhost(127.0.0.1), if you want to reach them through docker-host container. Use following docker command to get the bridge network gateway IP address
docker network inspect bridge --format='{{( index .IPAM.Config 0).Gateway}}'
Also be sure to configure your firewall of the host system to allow the dockerhost container to communicate with the host on your relevant port. Example
These examples will send messages from docker container to docker host with netcat
Start netcat server TCP on port 2323 to receive and display messages
nc 127.0.0.1 2323 -lkStart netcat server UDP on port 5353 to receive and display messages
nc 127.0.0.1 5353 -lk -u -w0Run the dockerhost container.
docker run --name 'dockerhost' \
--cap-add=NET_ADMIN --cap-add=NET_RAW \
--restart on-failure \
-d qoomon/docker-hostRun your application container and link the dockerhost container.
The dockerhost will be reachable through the domain/link dockerhost of the dockerhost container
docker run --rm \
--link 'dockerhost' \
-it alpine nc 'dockerhost' 2323 -vdocker run --rm \
--link 'dockerhost' \
-it alpine nc 'dockerhost' 5353 -u -vCreate 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-hostRun your application container within the dockerhost network.
The dockerhost will be reachable through the domain/link dockerhost of the dockerhost container
docker run --rm \
--link 'dockerhost' \
-it alpine nc 'dockerhost' 2323 -vdocker run --rm \
--link 'dockerhost' \
-it alpine nc 'dockerhost' 5353 -u -vversion: '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"]