Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup bridge0 and iptables automatically #24

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ Docker implemented in around 100 lines of bash.

The following packages are needed to run bocker.

* [bridge-utils][]
* btrfs-progs
* curl
* iproute2
* iptables
* libcgroup-tools
* [procps][]
* util-linux >= 2.25.2
* coreutils >= 7.5

Expand All @@ -24,9 +26,6 @@ Because most distributions do not ship a new enough version of util-linux you wi
Additionally your system will need to be configured with the following:

* A btrfs filesystem mounted under `/var/bocker`
* A network bridge called `bridge0` and an IP of 10.0.0.1/24
* IP forwarding enabled in `/proc/sys/net/ipv4/ip_forward`
* A firewall routing traffic from `bridge0` to a physical interface.

For ease of use a Vagrantfile is included which will build the needed environment.

Expand Down Expand Up @@ -142,3 +141,6 @@ GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

[bridge-utils]: http://sourceforge.net/projects/bridge/
[procps]: http://procps.sourceforge.net/
13 changes: 9 additions & 4 deletions bocker
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,20 @@ function bocker_run() { #HELP Create a container:\nBOCKER run <image_id> <comman
[[ "$(bocker_check "$1")" == 1 ]] && echo "No image named '$1' exists" && exit 1
[[ "$(bocker_check "$uuid")" == 0 ]] && echo "UUID conflict, retrying..." && bocker_run "$@" && return
cmd="${@:2}" && ip="$(echo "${uuid: -3}" | sed 's/0//g')" && mac="${uuid: -3:1}:${uuid: -2}"
sysctl net.ipv4.conf.all.forwarding=1
ip addr list dev bridge0 &> /dev/null || (
brctl addbr bridge0
ip addr add 10.0.0.1/24 dev bridge0
ip link set dev bridge0 up
iptables -t nat -A POSTROUTING -s 10.0.0.0/24 ! -o bridge0 -j MASQUERADE
)
ip link add dev veth0_"$uuid" type veth peer name veth1_"$uuid"
ip link set dev veth0_"$uuid" up
ip link set veth0_"$uuid" master bridge0
ip link set dev veth0_"$uuid" up master bridge0
ip netns add netns_"$uuid"
ip link set veth1_"$uuid" netns netns_"$uuid"
ip netns exec netns_"$uuid" ip link set dev lo up
ip netns exec netns_"$uuid" ip link set veth1_"$uuid" address 02:42:ac:11:00"$mac"
ip netns exec netns_"$uuid" ip addr add 10.0.0."$ip"/24 dev veth1_"$uuid"
ip netns exec netns_"$uuid" ip link set dev veth1_"$uuid" up
ip netns exec netns_"$uuid" ip link set dev veth1_"$uuid" up address 02:42:ac:11:00"$mac"
ip netns exec netns_"$uuid" ip route add default via 10.0.0.1
btrfs subvolume snapshot "$btrfs_path/$1" "$btrfs_path/$uuid" > /dev/null
echo 'nameserver 8.8.8.8' > "$btrfs_path/$uuid"/etc/resolv.conf
Expand Down