CoreOS vagrant での、docker0のアドレスを変更する

# 概要

* [Minimal Vagrantfile for CoreOS](https://github.com/coreos/coreos-vagrant)

で、起動した、CoreOS 上の docker0 のIPを変更したい。


# 結論

***/run/flannel_docker_opts.env***

```
DOCKER_OPTS="--fixed-cidr=192.168.100.0/24 --bip=192.168.100.5/24"
```

に以下の内容を書き込んで、docker daemonを再起動


```
sudo systemctl restart docker
```


# 環境

以下の環境でチェック

|OS|version|
|:-:|:-:|
|CoreOS|1032.1.0|


# 初期状態

起動して vagrant ssh した後に ip a  を実行した。
この時点では、docker0 は作られていない。


```
core@core-01 ~ $ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 08:00:27:a7:5e:9e brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic eth0
       valid_lft 82367sec preferred_lft 82367sec
    inet6 fe80::a00:27ff:fea7:5e9e/64 scope link
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 08:00:27:d4:1c:f9 brd ff:ff:ff:ff:ff:ff
    inet 172.17.8.101/24 brd 172.17.8.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fed4:1cf9/64 scope link
       valid_lft forever preferred_lft forever
```


docker run でubuntuを実行した後、コンテナ内のip a。
この時にdocker0が作られるようだ。

```
core@core-01 ~ $ docker run --rm -ti ubuntu:14.04.4 /bin/bash
root@b62652ce8cf5:/# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
7: eth0@if8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    link/ether 02:42:ac:12:00:02 brd ff:ff:ff:ff:ff:ff
    inet 172.18.0.2/16 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:acff:fe12:2/64 scope link tentative
       valid_lft forever preferred_lft forever
root@b62652ce8cf5:/#
```

docker run ubuntu実行後、CoreOS上で。

```
core@core-01 ~ $ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 08:00:27:a7:5e:9e brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic eth0
       valid_lft 82163sec preferred_lft 82163sec
    inet6 fe80::a00:27ff:fea7:5e9e/64 scope link
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 08:00:27:d4:1c:f9 brd ff:ff:ff:ff:ff:ff
    inet 172.17.8.101/24 brd 172.17.8.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fed4:1cf9/64 scope link
       valid_lft forever preferred_lft forever
4: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
    link/ether 02:42:f9:01:70:b9 brd ff:ff:ff:ff:ff:ff
    inet 172.18.0.1/16 scope global docker0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:f9ff:fe01:70b9/64 scope link
       valid_lft forever preferred_lft forever
```

# 設定ファイルについて

coreos内の設定ファイル
（ただし、変更ができないようだ）
/usr/lib64/systemd/system/docker.service

この中で、環境設定のファイルを読み込むことができる。
そのファイルに内容を書き込む


# docker0の変更

/run/flannel_docker_opts.env
に、以下の内容を書き込む

```
DOCKER_OPTS="--fixed-cidr=192.168.100.0/24 --bip=192.168.100.5/24"
```

docker daemonの再起動

```
sudo systemctl restart docker
```

CoreOS上でのip a

```
core@core-01 ~ $ sudo systemctl restart docker
core@core-01 ~ $ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 08:00:27:a7:5e:9e brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic eth0
       valid_lft 82064sec preferred_lft 82064sec
    inet6 fe80::a00:27ff:fea7:5e9e/64 scope link
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 08:00:27:d4:1c:f9 brd ff:ff:ff:ff:ff:ff
    inet 172.17.8.101/24 brd 172.17.8.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fed4:1cf9/64 scope link
       valid_lft forever preferred_lft forever
4: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
    link/ether 02:42:f9:01:70:b9 brd ff:ff:ff:ff:ff:ff
    inet 192.168.100.5/24 scope global docker0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:f9ff:fe01:70b9/64 scope link
       valid_lft forever preferred_lft forever
```



dockerでubuntuを実行

```
core@core-01 ~ $ docker run --rm -ti ubuntu:14.04.4 /bin/bash
root@253724d26c6f:/# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
9: eth0@if10: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    link/ether 02:42:c0:a8:64:01 brd ff:ff:ff:ff:ff:ff
    inet 192.168.100.1/24 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:c0ff:fea8:6401/64 scope link
       valid_lft forever preferred_lft forever
root@253724d26c6f:/#
```


# 参考情報

* [How to customize docker0 network options in Docker](https://blog.plein.org/2015/08/11/how-to-customize-docker0-network-options-in-docker/)