• Stars
    star
    1,027
  • Rank 44,704 (Top 0.9 %)
  • Language
    Shell
  • License
    MIT License
  • Created almost 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A docker sidecar container to forward all traffic to local docker host or any other host

docker-host Sparkline

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 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 using DNS names e.g. getent ahostsv4 host.docker.internal

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

⚠️ 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}}'

    NOTE: 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 -p 2323 -lk

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

nc -p 5353 -lk -u

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"]

External References

More Repositories

1

maven-git-versioning-extension

This extension will set project version, based on current Git branch or tag.
Java
278
star
2

git-conventional-commits

Git Conventional Commits Util to generate Semantic Version and Markdown Change Log and Validate Commit Messag
JavaScript
211
star
3

aws-s3-bucket-browser

Single page application to browse AWS S3 bucket content
HTML
181
star
4

aws-ssm-ec2-proxy-command

AWS SSM EC2 SSH Proxy Command
PowerShell
180
star
5

otp-authenticator-webapp

A 'Google Authenticator' like Single Page Application
JavaScript
93
star
6

zsh-lazyload

zsh plugin for lazy load commands and speed up start up time of zsh
Shell
78
star
7

gradle-git-versioning-plugin

This extension will set project version, based on current Git branch or tag.
Java
77
star
8

Jira-Issue-Card-Printer

Beautiful Issue Card Printer
JavaScript
69
star
9

banking-swift-messages-java

Banking SWIFT Library, MT Format Message Parser Writer SWIFT(Society for Worldwide Interbank Financial Telecommunication)
Java
29
star
10

time-timer-webapp

A CountDown and CountUp Timer
JavaScript
25
star
11

smart-life-webapp

JavaScript
20
star
12

my-zsh

handy and beautiful ZSH config
Shell
17
star
13

github-actions-access-manager

Manage access from GitHub actions workflows.
JavaScript
11
star
14

zjump

Simplify zsh directory navigation; jump to already visited, parent or sub folders.
Shell
10
star
15

zgem

zsh dependency manager 🐚 💎
Shell
10
star
16

unchecked-exceptions-java

Throw any Java Exception anywhere without the need of catching them nor wrapping them into RuntimeException
Java
7
star
17

aws-session

A CLI to generate and store session credentials in ~/.aws/credentials file, based on ~/.aws/config profiles
Python
6
star
18

aws-ec2-ssh-iam

AWS IAM managed EC2 SSH access
JavaScript
4
star
19

vercel-cors-proxy

JavaScript
3
star
20

gmail-rss-feed

Google Scripts Project to generate a RSS feed based on labeled emails
JavaScript
3
star
21

chrome-tab-multiselect-extension

JavaScript
3
star
22

meeting-cash-creep

Vue
3
star
23

userscript-kleinanzeigen-duplicate-ad

JavaScript
3
star
24

actions-publish-to-github-pages

GitHub Action to Publish Directory to GitHub Pages
Shell
3
star
25

chrome-tab-shift-extension

This extension will add a shortcuts to shift tabs.
JavaScript
2
star
26

junit-extension

Java JUnit Utils and Extentions
Java
2
star
27

domain-value-java

Domain Values
Java
2
star
28

zsh-theme-qoomon

zsh prompt theme
Shell
2
star
29

qoomon

About
2
star
30

zsh-history-search

zsh-history-search
Shell
2
star
31

aws-configure

A CLI to configure AWS named profiles in ~/.aws/config and ~/.aws/credentials files
Python
2
star
32

threema-web-desktop-app

Threema Standalone Web App with Dark and Light Mode Support
JavaScript
2
star
33

userscript-jira-dependency-indicators

JavaScript
2
star
34

kotlin-examples

Kotlin
2
star
35

userscript-aws-visual-account-indicator

This userscript reads the aws-userInfo cookie and adds account name and color indicator
JavaScript
2
star
36

aws-lambda-gitlab-webhook-to-datadog

JavaScript
2
star
37

userscript-jira-colored-labels

JavaScript
2
star
38

maven-enforcer-rules

maven-enforcer-rules
Java
2
star
39

chrome-tab-toggle-extension

This extension will add a shortcut to toggle through recent active tabs.
JavaScript
2
star
40

.github

1
star
41

chrome-new-tab-extension

Open neat blank page as 'New Tab' Page
HTML
1
star
42

chrome-search-engine-blocker-extension

Prevents Chrome from adding new search engines by opensearch link and search auto detection
JavaScript
1
star
43

diceware-webapp

HTML
1
star
44

userscript-disable-open-search

JavaScript
1
star
45

yolo-secret

TypeScript
1
star
46

chrome-show-password-extension

JavaScript
1
star
47

actions--set-env

TypeScript
1
star
48

cdn

cdn
JavaScript
1
star
49

self-signed-https-proxy

Shell
1
star
50

passphrase-generator

dice passphrase generator
Shell
1
star
51

google-chrome-launcher

Shell
1
star
52

chrome-tab-duplicate-extension

This extension will add a shortcut to duplicate tab.
JavaScript
1
star