|
| 1 | +# Using CNI with nerdctl |
| 2 | + |
| 3 | +nerdctl uses CNI plugins for its container network, you can set network by |
| 4 | +either `--network` or `--net` option. |
| 5 | + |
| 6 | +## Basic networks |
| 7 | + |
| 8 | +nerdctl support some basic types of CNI plugins without any configuration |
| 9 | +needed(you should have CNI plugin be installed), for Linux systems the basic |
| 10 | +CNI plugin types are `bridge`, `portmap`, `firewall`, `tuning`, for Windows |
| 11 | +system, the supported CNI plugin types are `nat` only. |
| 12 | + |
| 13 | +The default network `bridge` for Linux and `nat` for Windows if you |
| 14 | +don't set any network options. |
| 15 | + |
| 16 | +## Custom networks |
| 17 | + |
| 18 | +You can also customize your CNI network by providing configuration files. |
| 19 | +For example you have one configuration file(`/etc/cni/net.d/10-mynet.conf`) |
| 20 | +for `bridge` network: |
| 21 | + |
| 22 | +```json |
| 23 | +{ |
| 24 | + "cniVersion": "0.4.0", |
| 25 | + "name": "mynet", |
| 26 | + "type": "bridge", |
| 27 | + "bridge": "cni0", |
| 28 | + "isGateway": true, |
| 29 | + "ipMasq": true, |
| 30 | + "ipam": { |
| 31 | + "type": "host-local", |
| 32 | + "subnet": "172.19.0.0/24", |
| 33 | + "routes": [ |
| 34 | + { "dst": "0.0.0.0/0" } |
| 35 | + ] |
| 36 | + } |
| 37 | +} |
| 38 | +``` |
| 39 | + |
| 40 | +This will configure a new CNI network with the name `mynet`, and you can use |
| 41 | +this network to create a container: |
| 42 | + |
| 43 | +```console |
| 44 | +# nerdctl run -it --net mynet --rm alpine ip addr show |
| 45 | +1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000 |
| 46 | + link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 |
| 47 | + inet 127.0.0.1/8 scope host lo |
| 48 | + valid_lft forever preferred_lft forever |
| 49 | + inet6 ::1/128 scope host |
| 50 | + valid_lft forever preferred_lft forever |
| 51 | +3: eth0@if6120: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP |
| 52 | + link/ether 5e:5b:3f:0c:36:56 brd ff:ff:ff:ff:ff:ff |
| 53 | + inet 172.19.0.51/24 brd 172.19.0.255 scope global eth0 |
| 54 | + valid_lft forever preferred_lft forever |
| 55 | + inet6 fe80::5c5b:3fff:fe0c:3656/64 scope link tentative |
| 56 | + valid_lft forever preferred_lft forever |
| 57 | +``` |
| 58 | + |
| 59 | +## Bridge Isolation Plugin |
| 60 | + |
| 61 | +If you have the [CNI isolation plugin](https://github.com/AkihiroSuda/cni-isolation) installed, the `isolation` plugin will be used automatically. |
0 commit comments