Skip to content

Instantly share code, notes, and snippets.

@stv0g
Created January 24, 2020 15:34
Show Gist options
  • Save stv0g/43b23d7826fa0fba3f11921717ddb39a to your computer and use it in GitHub Desktop.
Save stv0g/43b23d7826fa0fba3f11921717ddb39a to your computer and use it in GitHub Desktop.
docker-netns.sh
#!/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