Skip to content

Instantly share code, notes, and snippets.

@gburd
Last active August 14, 2020 14:59
Show Gist options
  • Save gburd/8a8b9270317eb023a21fdea0adfa13f0 to your computer and use it in GitHub Desktop.
Save gburd/8a8b9270317eb023a21fdea0adfa13f0 to your computer and use it in GitHub Desktop.
Container sending data to host using net=bridge mode (e.g. container to localhost)

Rather than 127.0.0.1 I think that the route to the Docker host is always available within the container in bridge mode as the default route, so you just have to find it, here's how:

$ nc -lu 8125
$ docker run --rm -it ubuntu:latest /bin/bash
# apt install net-tools netcat
# export DOCKER_HOST_IP=$(route -n | awk '/UG[ \t]/{print $2}')
# echo 'Over here!' | nc -w 0 -u $DOCKER_HOST_IP 8125

And so we have the container send data over UDP to the default route which is the host (when docker container is run with net=bridge, the default).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment