Networking overview
Quote
It seems once people understand the basics of containers, networking is one of the first aspects they begin experimenting with. And regarding networking, it takes very little experimentation before ending up on the deep end of the pool.
This section deals with one of the more comprehensive topics when working with containers. Readers with experience from networking in Docker should expect a substantially different approach; see Kleene for Docker users for an overview of the differences. This page gives a brief introduction to the ideas related to networking and the remaining parts of the networking chapter cover them in more detail.
The two central concepts of container networking are: Networks and network driver. The former are independent objects in Kleene and the latter is a property of containers. Networks are used to provide different kinds of connectivity to containers, and the capabilities of using networks, and networking in general, is determined by which kind of network driver the container has.
Network types¶
Three different kinds of networks exists, and each network is represented by an interface on the host.
-
loopback: Kleene creates a loopback interface on the host for the network. This has historically been a classical way to provide networking for jails in FreeBSD. It is the default network type with Klee. -
bridge: Kleene creates a bridge interface on the host for the network. The bridge network can be used to (logically) link interfaces on the host machine (physical or virtual). The bridge network is used for containers with thevnetnetwork driver (see below). -
custom: The user determines which interface on the host should be used for the network. For instance, if the container should have an IP directly on the physical interface, the default loopback interface (lo0) or more exotic use cases. The user is expected to take care of creating/destroying the interface, if needed.
Container network drivers¶
The networking capabilities of a container is determined by it's network driver. There are four different network drivers, and only one can be used at the same time. The drivers are derived directly from the underlying jail-parameters.
-
host(default driver): Inherit the network configuration from the host. The container is able to see all ips of all interfaces. However, the container can't manipulate the interfaces, such as adding/remove IP-addresses withifconfigetc. This network driver provides the least amount of isolation since the container can see (and use) all IP-addresses on the host, including those used by other containers. It is not possible to connect to any networks with this driver, and since it does not require a network, it is the default driver. However, in production setups it is recommended to use networks and theipnet/vnetdrivers drivers instead, since they provide much better isolation from the host and other containers. -
ipnet: Inherit the network configuration from the host, but restrict which IP addresses of the host that are accessible to the container. All interfaces of the host are visible within the container but not the IP's. Only assigned IP's are visible within the container, and configuring network interfaces using tools such asifconfig(8)is prohibited. A few pros and cons ofipnetcontainers: -
It is lightweight way of providing connectivity to a container while retaining isolation from the host and other containers.
-
ipnetcontainers can connect to all network types. -
The IP's assigned to the container is also visible from the host so getting an overview of IP usage of
ipnetcontainers is straightforward. -
Access to localhost aka.
127.0.0.1is prohibited by default. This might require additional configuration of applications that expects this IP to be accessible. -
The restricted networking environment limits the possibilities of what you can do within the container. For instance, it is not possible to setup a firewall or manipulating routes, network interfaces etc. Use the
vnetdriver in that case. -
vnet:vnetcontainers have their own virtual network stack, such as a dedicatedloopbackinterface, routing table, firewall capabilities etc.vnetcontainers are connected through a virtualcross-overcable represented by a pair ofepair(4)interfaces. One of these is designated to the container and the other resides on the host, where it is added to abridgeinterface. A few pros and cons ofvnetcontainers: -
Because
vnetcontainers have their own network stack, they can create virtual interfaces, manipulate existing ones, and run their own firewall. This makes them ideal for more complicated networking requirements. -
Slightly more host and container configuration is needed compared to
ipnetcontainers since epair interfaces has to be allocated/configured and gateways has to be added during container startup. -
Since the network-stack is isolated from the host, the networking configuration of the container is only visible from within the container.
-
vnetcontainers can only connect to bridge-networks. -
disabled: Networking capabilities are disabled. Containers using this driver can see all network interfaces of the host but none of the IP-addresses.
Next steps¶
Go to on of driver-specific pages for introductory walk-throughs:
If you have experience with FreeBSD jails and know the different approaches to networking, the walk-throughs should be very familiar and hopefully it shows how Kleene incorporates it.