Container Network Interface - networking for Linux containers
Go to file
Casey Callendrello ee7c96f201
Merge pull request #1152 from architkulkarni/status-codes
Add error codes for STATUS verb to `types.go` and `SPEC.md`
2025-06-02 17:11:33 +02:00
.github build(deps): bump github/codeql-action from 3.26.4 to 3.26.7 2024-09-16 00:12:22 +00:00
Documentation cleanup: update references, make links relative 2023-12-05 12:50:31 +01:00
cnitool Remove accidentally-committed cnitool binary 2024-08-28 09:04:46 -04:00
libcni libcni: remove some deprecation warnings 2025-04-07 17:34:18 +02:00
mk Update golangci-lint to v1.57.1 2024-05-13 16:40:38 +02:00
pkg Merge pull request #1152 from architkulkarni/status-codes 2025-06-02 17:11:33 +02:00
plugins Use type aliases to hint deprecation for old API types (#928) 2024-06-17 11:45:13 -04:00
scripts Docs: remove obsolete information about building release artifacts 2024-03-17 21:32:20 +01:00
.gitattributes Switch from Travis to GH Actions 2021-02-03 17:48:44 +01:00
.gitignore Remove accidentally-committed cnitool binary 2024-08-28 09:04:46 -04:00
.golangci.yml enable gocritic linter 2023-10-18 07:43:38 +02:00
.yamllint.yaml Setup scorecard workflow 2024-08-28 15:01:51 +00:00
CODE-OF-CONDUCT.md cleanup: update references, make links relative 2023-12-05 12:50:31 +01:00
CONTRIBUTING.md cleanup: update references, make links relative 2023-12-05 12:50:31 +01:00
CONVENTIONS.md cleanup: update references, make links relative 2023-12-05 12:50:31 +01:00
DCO Add DCO and CONTRIBUTING.md 2015-09-02 11:00:27 -07:00
GOVERNANCE.md governance: add notes about public voting 2017-09-13 17:24:40 -05:00
LICENSE Initial commit 2015-04-04 20:35:49 -07:00
MAINTAINERS Update my email 2025-04-22 11:20:07 -04:00
Makefile Define Makefile with golangci-lint 2023-10-18 07:44:03 +02:00
README.md remove archived 3rd party plugins 2025-03-16 03:48:34 +01:00
RELEASING.md Docs: remove obsolete information about building release artifacts 2024-03-17 21:32:20 +01:00
ROADMAP.md Update roadmap for 1.0 plans 2020-01-29 16:20:26 +00:00
SPEC.md Merge pull request #1152 from architkulkarni/status-codes 2025-06-02 17:11:33 +02:00
go.mod build(deps): bump the golang group across 1 directory with 2 updates 2024-08-26 00:39:46 +00:00
go.sum build(deps): bump the golang group across 1 directory with 2 updates 2024-08-26 00:39:46 +00:00
logo.png Add CNI Logo to README 2017-05-15 08:18:23 -05:00
test.sh Define Makefile with golangci-lint 2023-10-18 07:44:03 +02:00

README.md

CNI Logo


CNI - the Container Network Interface

CII Best Practices OpenSSF Scorecard

What is CNI?

CNI (Container Network Interface), a Cloud Native Computing Foundation project, consists of a specification and libraries for writing plugins to configure network interfaces in Linux containers, along with a number of supported plugins. CNI concerns itself only with network connectivity of containers and removing allocated resources when the container is deleted. Because of this focus, CNI has a wide range of support and the specification is simple to implement.

As well as the specification, this repository contains the Go source code of a library for integrating CNI into applications and an example command-line tool for executing CNI plugins. A separate repository contains reference plugins and a template for making new plugins.

The template code makes it straight-forward to create a CNI plugin for an existing container networking project. CNI also makes a good framework for creating a new container networking project from scratch.

Here are the recordings of two sessions that the CNI maintainers hosted at KubeCon/CloudNativeCon 2019:

Contributing to CNI

We welcome contributions, including bug reports, and code and documentation improvements. If you intend to contribute to code or documentation, please read CONTRIBUTING.md. Also see the contact section in this README.

The CNI project has a weekly meeting. It takes place Mondays at 11:00 US/Eastern. All are welcome to join.

Why develop CNI?

Application containers on Linux are a rapidly evolving area, and within this area networking is not well addressed as it is highly environment-specific. We believe that many container runtimes and orchestrators will seek to solve the same problem of making the network layer pluggable.

To avoid duplication, we think it is prudent to define a common interface between the network plugins and container execution: hence we put forward this specification, along with libraries for Go and a set of plugins.

Who is using CNI?

Container runtimes

3rd party plugins

The CNI team also maintains some core plugins in a separate repository.

How do I use CNI?

Requirements

The CNI spec is language agnostic. To use the Go language libraries in this repository, you'll need a recent version of Go. You can find the Go versions covered by our automated tests in .travis.yaml.

Reference Plugins

The CNI project maintains a set of reference plugins that implement the CNI specification. NOTE: the reference plugins used to live in this repository but have been split out into a separate repository as of May 2017.

Running the plugins

After building and installing the reference plugins, you can use the priv-net-run.sh and docker-run.sh scripts in the scripts/ directory to exercise the plugins.

note - priv-net-run.sh depends on jq

Start out by creating a netconf file to describe a network:

$ mkdir -p /etc/cni/net.d
$ cat >/etc/cni/net.d/10-mynet.conf <<EOF
{
	"cniVersion": "0.2.0",
	"name": "mynet",
	"type": "bridge",
	"bridge": "cni0",
	"isGateway": true,
	"ipMasq": true,
	"ipam": {
		"type": "host-local",
		"subnet": "10.22.0.0/16",
		"routes": [
			{ "dst": "0.0.0.0/0" }
		]
	}
}
EOF
$ cat >/etc/cni/net.d/99-loopback.conf <<EOF
{
	"cniVersion": "0.2.0",
	"name": "lo",
	"type": "loopback"
}
EOF

The directory /etc/cni/net.d is the default location in which the scripts will look for net configurations.

Next, build the plugins:

$ cd $GOPATH/src/github.com/containernetworking/plugins
$ ./build_linux.sh # or build_windows.sh

Finally, execute a command (ifconfig in this example) in a private network namespace that has joined the mynet network:

$ CNI_PATH=$GOPATH/src/github.com/containernetworking/plugins/bin
$ cd $GOPATH/src/github.com/containernetworking/cni/scripts
$ sudo CNI_PATH=$CNI_PATH ./priv-net-run.sh ifconfig
eth0      Link encap:Ethernet  HWaddr f2:c2:6f:54:b8:2b  
          inet addr:10.22.0.2  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::f0c2:6fff:fe54:b82b/64 Scope:Link
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:1 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:1 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:90 (90.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

The environment variable CNI_PATH tells the scripts and library where to look for plugin executables.

Running a Docker container with network namespace set up by CNI plugins

Use the instructions in the previous section to define a netconf and build the plugins. Next, docker-run.sh script wraps docker run, to execute the plugins prior to entering the container:

$ CNI_PATH=$GOPATH/src/github.com/containernetworking/plugins/bin
$ cd $GOPATH/src/github.com/containernetworking/cni/scripts
$ sudo CNI_PATH=$CNI_PATH ./docker-run.sh --rm busybox:latest ifconfig
eth0      Link encap:Ethernet  HWaddr fa:60:70:aa:07:d1  
          inet addr:10.22.0.2  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::f860:70ff:feaa:7d1/64 Scope:Link
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:1 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:1 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:90 (90.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

What might CNI do in the future?

CNI currently covers a wide range of needs for network configuration due to its simple model and API. However, in the future CNI might want to branch out into other directions:

  • Dynamic updates to existing network configuration
  • Dynamic policies for network bandwidth and firewall rules

If these topics are of interest, please contact the team via the mailing list or IRC and find some like-minded people in the community to put a proposal together.

Where are the binaries?

The plugins moved to a separate repo: https://github.com/containernetworking/plugins, and the releases there include binaries and checksums.

Prior to release 0.7.0 the cni release also included a cnitool binary; as this is a developer tool we suggest you build it yourself.

Contact

For any questions about CNI, please reach out via:

Security

If you have a security issue to report, please do so privately to the email addresses listed in the MAINTAINERS file.