<commit_before># Tutorial on using CoreOS Flannel for Docker networking
## CoreOS
 + Lightweight OS based on Gentoo Linux
 + Has a distributed key-value store at the core
 + Read-only rootfs. Writeable /etc
   + All services are in containers
## Flannel Basic
 + One CIDR subnet per machine, like Kubernestes
 + No Docker port-based mapping
 + Containers reach each other through IP
 + Packets encapsulated using UDP, and soon VxLAN
 ![](https://raw.githubusercontent.com/huanpc/IoT-1/master/docs/images/flannel_01.png)
### Instructions to run Flannel
1. Build flannel on each host
```bash
$ git clone https://github.com/coreos/flannel.git
$ cd flannel
$ docker run -v `pwd`:/opt/flannel -it google/golang /bin/bash -c "cd /opt/flannel && ./build"
```
2. Set key in etcd for network config
```bash
$ curl -L http://127.0.0.1:4001/v2/keys/coreos.com/network/config -XPUT -d value='{
    "Network": "10.0.0.0/8",
    "SubnetLen": 20,
    "SubnetMin": "10.10.0.0",
    "SubnetMax": "10.99.0.0",
    "Backend": {
        "Type": "udp",
        "Port": 7890}}'
```
3. Start flannel
 - flanneld port created and route is set for the full flat IP range
```bash
$ sudo ./bin/flanneld &
```
4. Restart docker daemon with appropriate bridge IP
```bash
$ source /run/flannel/subnet.env
$ sudo ifconfig docker0 ${FLANNEL_SUBNET}
$ sudo docker -d --bip=${FLANNEL_SUBNET} --mtu=${FLANNEL_MTU} &
```
### Testing Flannel Networking 
![Testing](https://raw.githubusercontent.com/huanpc/IoT-1/master/docs/images/flannel_02.jpg)
<commit_msg>Update flannel.md<commit_after># Tutorial on using CoreOS Flannel for Docker networking
## CoreOS
 + Lightweight OS based on Gentoo Linux
 + Has a distributed key-value store at the core
 + Read-only rootfs. Writeable /etc
   + All services are in containers
   
## Flannel Basic
 + One CIDR subnet per machine, like Kubernestes
 + No Docker port-based mapping
 + Containers reach each other through IP
 + Packets encapsulated using UDP, and soon VxLAN
 ![](https://raw.githubusercontent.com/huanpc/IoT-1/master/docs/images/flannel_01.png)
 
### Instructions to run Flannel
1. Build flannel on each host
```bash
$ git clone https://github.com/coreos/flannel.git
$ cd flannel
$ docker run -v `pwd`:/opt/flannel -it google/golang /bin/bash -c "cd /opt/flannel && ./build"
```
2. Set key in etcd for network config
```bash
$ curl -L http://127.0.0.1:4001/v2/keys/coreos.com/network/config -XPUT -d value='{
    "Network": "10.0.0.0/8",
    "SubnetLen": 20,
    "SubnetMin": "10.10.0.0",
    "SubnetMax": "10.99.0.0",
    "Backend": {
        "Type": "udp",
        "Port": 7890}}'
```
3. Start flannel
 - flanneld port created and route is set for the full flat IP range
```bash
$ sudo ./bin/flanneld &
```
4. Restart docker daemon with appropriate bridge IP
```bash
$ source /run/flannel/subnet.env
$ sudo ifconfig docker0 ${FLANNEL_SUBNET}
$ sudo docker -d --bip=${FLANNEL_SUBNET} --mtu=${FLANNEL_MTU} &
```
### Testing Flannel Networking 
![Testing](https://raw.githubusercontent.com/huanpc/IoT-1/master/docs/images/flannel_02.jpg)

{'fraction_non_alphanumeric': 0.14035646085295989, 'fraction_numerical': 0.02928071292170592, 'mean_word_length': 3.2187919463087247, 'pattern_counts': {'":': 14, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 8, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6910257', 'n_tokens_mistral': 1218, 'n_tokens_neox': 1102, 'n_words': 317}