github.com/john-lin/cni@v0.6.0-rc1.0.20170712150331-b69e640cc0e2/scripts/docker-run.sh (about)

     1  #!/bin/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