s4ros

docker_network_bridge_macvlan.sh

Nov 25th, 2020
506
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. set -x
  4.  
  5. set -u
  6. set -e
  7. set -o pipefail
  8.  
  9. ETH_INT=$(ip route | grep ^default | cut -d ' ' -f 5)
  10. IP_GW=$(ip route | grep ^default | cut -d ' ' -f 3)
  11. IP_BASE=${IP_GW%.*}
  12.  
  13. sudo ip link add bridge2 link ${ETH_INT} type macvlan mode bridge
  14. sudo ip link set bridge2 up
  15. sudo ip addr add ${IP_BASE}.192/29 dev bridge2
  16. docker network create -d macvlan -o parent=${ETH_INT} --gateway ${IP_GW} --subnet ${IP_BASE}.0/24 --ip-range ${IP_BASE}.198/30 bridge2
  17. docker run --rm --name nginx -itd --network bridge2 nginx:alpine
  18. sleep 2
  19. curl ${IP_BASE}.196
  20.  
  21. # docker kill nginx
  22. # docker network rm bridge2
  23. # sudo ip link delete bridge2
RAW Paste Data