Skip to content

Instantly share code, notes, and snippets.

@aojea
Last active January 22, 2024 07:43
Show Gist options
  • Save aojea/f6cc93adaf98df783073b2b9b0f0a56a to your computer and use it in GitHub Desktop.
Save aojea/f6cc93adaf98df783073b2b9b0f0a56a to your computer and use it in GitHub Desktop.
Podman networkless containers

Podman networless containers

There are some special cases that you only want to create a container without network interfaces, so you can handle the network directly.

Podman networking uses CNI to configure the networking of the containers, so we can leverage that to create containers without network interfaces, however, we always need the special loopback interface to be UP, so the networking working inside of the namespace.

How to create a networkless container

Podman creates the network configuration in a special folder. We can create a file directly on that folder, or we can modify the files in that folder to suit our needs. Let's see how this works:

  1. Create a new podman network, it will output the network configuration file
$ podman network create networkless
/etc/cni/net.d/networkless.conflist
  1. Modify the network configuration file from previous command, to handle ONLY the loopback interface, replacing it by this file:
{
   "cniVersion": "0.4.0",
   "name": "networkless",
   "plugins": [
    {
      "type": "loopback"
    }
   ]
}
  1. Now we can use that network to create networkless containers:
podman run --network networkless -it alpine ash
/ # ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000
    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

... and now what

Now you can use something to create the network between the containers, I personally use https://github.com/redhat-nfvpe/koko for this, but it's just "simply" linux namespaces networking ;) ...

Have fun, possibilities are infinite now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment