Created
January 24, 2020 15:34
-
-
Save stv0g/43b23d7826fa0fba3f11921717ddb39a to your computer and use it in GitHub Desktop.
docker-netns.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Install jq!!! | |
# | |
# | |
command -v jq >/dev/null 2>&1 || echo >&2 'Please install "jq": apt-get install jq' | |
NETNS="blue" | |
# Create docker networks if they not exist yet | |
docker network create -o com.docker.network.bridge.name=defnet defnet | true | |
docker network create -o com.docker.network.bridge.name=blunet blunet | true | |
# Create network namespace | |
ip netns add ${NETNS} | |
# Start containers | |
docker-compose up -d | |
# Attach all containers network interfaces to the blue netns | |
for IF in $(ip -j link show master blunet type veth | jq -r .[].ifname); do | |
ip link set dev ${IF} netns ${NETNS} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment