#!/bin/bash set -e set -x base="$( cd "$(dirname "$0")" ; pwd -P )" id="$1" public_ip="$2" public_iface="$3" if [ -z "$public_iface" ]; then echo >&2 "usage: $0 ctid public_ip public_iface" exit 1 fi $base/remove_public_route "$id" "$public_ip" "$public_iface" || true docker_ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $id) if [ -n "$docker_ip" ]; then iptables -t nat -A PREROUTING -d $public_ip/32 -i $public_iface -j DNAT --to-destination $docker_ip fi exit 0