GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - zanettea/docker-redirect: Redirects traffic directed to a containerized service to a local service under test

BranchesTags
Open more actions menu

Latest commit

 

History

5 Commits
5 Commits

Folders and files

NameName
Last commit message
Last commit date
LICENSE
LICENSE
 
 
README.md
README.md
 
 
docker_redirect.sh
docker_redirect.sh
 
 

Repository files navigation

docker-redirect

Redirects traffic directed to a containerized service to a local service under test so that the local instance can transparently take over the containerized instance serving client requests.

The script has been tested in Linux, Mac and Windows (WSL2) environments.

      +-----------------+      +-----------------+
      |                 |      |                 |
      |  Containerized  |      |    Service X    |
      |    Service X    |      |    under test   |
      |                 |      |                 |
      |   +---------+   |      |   +---------+   |
      |   | Port N  |   |      |   | Port M  |   |
      +---+---------+---+      +---+---------+---+
              |                         ^
            XXXXX        Redirect       |
              +-+-----------------------+
              | |
              | |
         +----------+
         |          |
         |  Client  |
         |          |
         +----------+

Usage:

docker_redirect [start|stop] [filter_key] [docker_internal_port =>] [=> local_port]

Example

Consider MyService is an HTTP service of a microservice application running in a container and exposing port 80 to local port 8080:

docker run --name MyService -p 8080:80

If you want to test a development version of the service in the same test enviroment without redeploying the container you can use docker-redirect script. If the MyService under test is running on local port 8081:

docker_redirect start MyService 80 8081

In this way all the requests targeting the service will be transparently redirected to the version under test.

To disable the redirect and restore the normal communication:

docker_redirect stop

How it works

IPTables are used to redirect all TCP traffic targeted at the container IP address and port to local ip and port:

 $IPTABLES -t nat -A PREROUTING -p tcp -d $IP --dport $DOCKER_PORT  -j DNAT --to $LOCAL_IP:$LOCAL_PORT
 $IPTABLES -t nat -n -L PREROUTING

This actually works in Windows (WSL2) and Mac platforms as well because the iptables commands run in a privileged docker container with host networking.

About

Redirects traffic directed to a containerized service to a local service under test

Resources

Readme
MIT license
Activity

Stars

6 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.