Skip to content

Commit

Permalink
Set DOCKER_HOST manually to forward to arbitrary destinations
Browse files Browse the repository at this point in the history
  • Loading branch information
Torben Weibert committed Jan 16, 2019
1 parent 52c0ce4 commit f86ddfe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Docker image to forward all traffic to the docker host
* uses dns entry `host.docker.internal` if 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.

[![Build Status](https://travis-ci.org/qoomon/docker-host.svg?branch=master)](https://travis-ci.org/qoomon/docker-host)
[![Docker Stars](https://img.shields.io/docker/pulls/qoomon/docker-host.svg)](https://hub.docker.com/r/qoomon/docker-host/)

Expand Down
12 changes: 8 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#!/bin/sh
set -e

DOCKER_HOST="$(getent hosts host.docker.internal | cut -d' ' -f1)"
if [ $DOCKER_HOST ]; then
echo "Docker Host: $DOCKER_HOST (host.docker.internal)"
echo "Docker Host: $DOCKER_HOST (manual override)"
else
DOCKER_HOST=$(ip -4 route show default | cut -d' ' -f3)
echo "Docker Host: $DOCKER_HOST (default gateway)"
DOCKER_HOST="$(getent hosts host.docker.internal | cut -d' ' -f1)"
if [ $DOCKER_HOST ]; then
echo "Docker Host: $DOCKER_HOST (host.docker.internal)"
else
DOCKER_HOST=$(ip -4 route show default | cut -d' ' -f3)
echo "Docker Host: $DOCKER_HOST (default gateway)"
fi
fi

FORWARDING_PORTS=${PORTS:-'0:65535'}
Expand Down

0 comments on commit f86ddfe

Please sign in to comment.