Networking in podman 4.x
podman 4.0 has a new networking stack. It uses Netavark for network setup (this is a direct replacement for CNI), and also uses Aardvark DNS server. Both of these tools are written from scratch in Rust keeping the requirements of podman in mind.
At the time of writing this blog post, we have podman-4.4.1 in Fedora 37, and podman-4.2.0 in Almalinux9.
Communication between two rootless containers
The default network for podman
is called podman
, this does not allow DNS based access between containers.
$ podman network ls
NETWORK ID NAME DRIVER
2f259bab93aa podman bridge
$ podman network inspect podman
[
{
"name": "podman",
"id": "2f259bab93aaaaa2542ba43ef33eb990d0999ee1b9924b557b7be53c0b7a1bb9",
"driver": "bridge",
"network_interface": "podman0",
"created": "2023-02-20T07:36:58.054055322Z",
"subnets": [
{
"subnet": "10.88.0.0/16",
"gateway": "10.88.0.1"
}
],
"ipv6_enabled": false,
"internal": false,
"dns_enabled": false,
"ipam_options": {
"driver": "host-local"
}
}
]
This means if we start two containers, they will not be able to communicate with each other via their names.
The solution is to create a new network and use it.
$ podman network create project1
project1
$ podman network inspect project1
[
{
"name": "project1",
"id": "1f0135a4fc3b1e58c1c8fcac762b15eb89a755959a4896fd321fa17f991de9fa",
"driver": "bridge",
"network_interface": "podman1",
"created": "2023-02-17T22:19:22.80494367Z",
"subnets": [
{
"subnet": "10.89.0.0/24",
"gateway": "10.89.0.1"
}
],
"ipv6_enabled": false,
"internal": false,
"dns_enabled": true,
"ipam_options": {
"driver": "host-local"
}
}
]
Noticed the dns_enabled
is now true
.
Let us test this out. We
$ podman run --rm -it --network project1 --name server42 fedora:37
[root@fc1869d78823 /]# cd /tmp/
[root@fc1869d78823 tmp]# mkdir hello
[root@fc1869d78823 tmp]# cd hello/
[root@fc1869d78823 hello]# echo "SELinux for win." > index.html
[root@fc1869d78823 hello]# python3 -m http.server
Serving HTTP on 0.0.0.0 port 8000 (https://0.0.0.0:8000/) ...
When we start this container, podman
starts aardvark-dns
automatically.
$ ps aux | grep aard
almalin+ 1205 0.0 0.0 276428 212 ? Ssl Feb18 0:00 /usr/libexec/podman/aardvark-dns --config /run/user/1000/containers/networks/aardvark-dns -p 53 run
Now, we can start a second container on the same network and use the magical tool curl
to fetch the data.
$ podman run --rm -it --network project1 fedora:37
[root@720fc9e63d72 /]# curl https://server42:8000/
SELinux for win.
As I heard, from the next release (4.5.0) of podman
, we will be able to use
DNS based communication even in the default network.