add_public_route 522 B

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