Debian Codegraph @

scripts/docker-run.sh

raw
1 #!/usr/bin/env bash
2
3 # Run a docker container with network namespace set up by the
4 # CNI plugins.
5
6 # Example usage: ./docker-run.sh --rm busybox /sbin/ifconfig
7
8 contid=$(docker run -d --net=none busybox:latest /bin/sleep 10000000)
9 pid=$(docker inspect -f '{{ .State.Pid }}' $contid)
10 netnspath=/proc/$pid/ns/net
11
12 ./exec-plugins.sh add $contid $netnspath
13
14 function cleanup() {
15 ./exec-plugins.sh del $contid $netnspath
16 docker rm -f $contid >/dev/null
17 }
18 trap cleanup EXIT
19
20 docker run --net=container:$contid $@
21