├── .gitignore ├── README.md ├── Vagrantfile └── network-namespace-2 ├── bridge.sh └── bridge_reset.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # make-container-without-docker 2 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | BOX_IMAGE = "bento/ubuntu-18.04" 2 | HOST_NAME = "ubuntu1804" 3 | 4 | $pre_install = <<-SCRIPT 5 | echo ">>>> pre-install <<<<<<" 6 | sudo apt-get update && 7 | sudo apt-get -y install gcc && 8 | sudo apt-get -y install make && 9 | sudo apt-get -y install pkg-config && 10 | sudo apt-get -y install libseccomp-dev && 11 | sudo apt-get -y install tree && 12 | sudo apt-get -y install jq && 13 | sudo apt-get -y install bridge-utils 14 | 15 | echo ">>>> install go <<<<<<" 16 | curl -O https://storage.googleapis.com/golang/go1.15.7.linux-amd64.tar.gz > /dev/null 2>&1 && 17 | tar xf go1.15.7.linux-amd64.tar.gz && 18 | sudo mv go /usr/local/ && 19 | echo 'PATH=$PATH:/usr/local/go/bin' | tee /home/vagrant/.bash_profile 20 | 21 | echo ">>>>> install docker <<<<<<" 22 | sudo apt-get -y install apt-transport-https ca-certificates curl gnupg-agent software-properties-common > /dev/null 2>&1 && 23 | sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - && 24 | sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" && 25 | sudo apt-get update && 26 | sudo apt-get -y install docker-ce docker-ce-cli containerd.io > /dev/null 2>&1 27 | SCRIPT 28 | 29 | Vagrant.configure("2") do |config| 30 | 31 | config.vm.define HOST_NAME do |subconfig| 32 | subconfig.vm.box = BOX_IMAGE 33 | subconfig.vm.hostname = HOST_NAME 34 | subconfig.vm.network :private_network, ip: "192.168.104.2" 35 | subconfig.vm.provider "virtualbox" do |v| 36 | v.memory = 1536 37 | v.cpus = 2 38 | end 39 | subconfig.vm.provision "shell", inline: $pre_install 40 | end 41 | 42 | end 43 | 44 | -------------------------------------------------------------------------------- /network-namespace-2/bridge.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ip netns add RED; 4 | ip link add reth0 netns RED type veth peer name reth1 5 | 6 | ip netns add BLUE; 7 | ip link add beth0 netns BLUE type veth peer name beth1 8 | 9 | ip link add br0 type bridge 10 | ip link set reth1 master br0 11 | ip link set beth1 master br0 12 | 13 | ip netns exec RED ip addr add 11.11.11.2/24 dev reth0 14 | ip netns exec BLUE ip addr add 11.11.11.3/24 dev beth0 15 | 16 | ip netns exec RED ip link set reth0 up; 17 | ip link set reth1 up; 18 | ip netns exec BLUE ip link set beth0 up; 19 | ip link set beth1 up; 20 | ip link set br0 up; 21 | 22 | iptables -t filter -A FORWARD -s 11.11.11.0/24 -j ACCEPT 23 | -------------------------------------------------------------------------------- /network-namespace-2/bridge_reset.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ip netns del RED; 4 | ip netns del BLUE; 5 | ip link del br0; 6 | ip link del beth1; 7 | ip link del reth1; 8 | 9 | iptables -t filter -D FORWARD -s 11.11.11.0/24 -j ACCEPT 10 | --------------------------------------------------------------------------------