Networking and pods

Network modes, the rootless networking helper (pasta or slirp4netns), user-defined networks with DNS by name, publishing ports safely, pods, connectivity troubleshooting and production network layouts.
PodmanNetworkingpastaDNSPodsCore hour

Hour overview

Containers reach each other and the outside world through their network namespaces. In this hour you choose how the sample service is connected: on a private network where other containers find it by name, published to one address on the host, or grouped in a pod that shares its localhost. You also learn the rootless networking helper, which differs between Podman 4 and Podman 5, and the checks that find a broken connection.

Time allocation. Network modes and the rootless helper 10, user-defined networks 10, publishing ports 12, pods 12, connectivity troubleshooting 10, production layout 6.

Objectives. By the end of the hour you can:

  • choose a network mode for a container and say what it isolates and what it exposes
  • identify the rootless networking helper on your host, and what it means for port forwarding
  • create a user-defined network, and reach a container from another one by name
  • publish a port on one address, and explain why low ports need a system setting when rootless
  • run containers in a pod that share localhost, and reach one from another
  • find the cause of a connection failure in a fixed order

Prerequisite. The image from hour 2. Remove containers from earlier hours with podman ps -a before you start.

Modules

Network modes and the rootless helper

Hour 5 · 00–10 · 10 min

The --network option picks how a container's network namespace is connected:

ModeMeaningUse it for
defaultthe default network that Podman createssimple single containers
a named networkyour own network, with DNS by container nameservices that talk to each other
noneno network, only loopbackbatch jobs that need no network
hostshares the host's network namespacerare, when the app must bind host interfaces
container:NAMEshares the network namespace of another containera helper that joins an existing service

Test the isolation of none. The container sees only the loopback interface:

podman run --rm --network none docker.io/library/alpine:3.20 ip addr

Expected: the output lists only lo, the loopback interface. There is no route to the outside.

The rootless helper. A rootless container cannot configure the host network directly, so Podman uses a helper process for outbound traffic and port forwarding. Podman 5.0 made pasta the default helper for rootless containers. Podman 4.x, including the 4.9.3 that Ubuntu 24.04 ships, uses slirp4netns. Check which one your host uses:

podman info

Expected: the networking section of podman info names the helper in use, pasta or slirp4netns. Containers keep the helper they were created with, so a container created on 4.x keeps slirp4netns after an upgrade to 5.x.

The difference matters when you debug. Source IP addresses seen by the service can differ between the two helpers, and some older tools assume slirp4netns. If a published port works on one host and not on another, compare the helpers first.

Common errors.

  • The container has no outside access under none: that is the mode working as intended. Choose a named network if the container needs to reach services.
  • podman info does not name the helper: the field name differs by version. Look for pasta or slirp4netns in the networking section.

Production note. Use none for jobs that need no network, and named networks for services. Use host only with a documented reason.

User-defined networks and DNS

Hour 5 · 10–20 · 10 min

A user-defined network gives every container on it a DNS name that matches its container name. The default network does not do that. The lab proves the difference: a service that is reachable by name on appnet is not reachable by name on the default network.

podman network create appnet
podman network ls
podman run -d --name web --network appnet localhost/podman-app:dev
podman run --rm --network appnet docker.io/library/alpine:3.20 wget -qO- http://web:8000/health
podman run --rm docker.io/library/alpine:3.20 wget -qO- http://web:8000/health

Expected: the first wget prints {"status": "ok"}. The second fails with an error such as bad address 'web:8000', because web is not on the default network. Note that no port was published: the service is reachable only by containers on appnet.

Inspect the network and see which containers are attached:

podman network inspect appnet

Expected: JSON that lists web under its containers, with an IP address on the network's subnet.

Clean up:

podman rm -f web
podman network rm appnet

Expected: the network is removed. Podman refuses to remove a network that still has containers.

Put a database and the services that use it on one user-defined network, and publish only the service that users reach. The database then never appears on the host's ports.

Common errors.

  • bad address on a name: the containers are on different networks. Check with podman network inspect on each network.
  • network is in use on removal: a container still uses it. Remove the container first.

Production note. Create one network per application, with a name that says what it is, such as orders-backend.

Publishing ports

Hour 5 · 20–32 · 12 min

Publishing maps a host port to a container port. The address you publish on matters as much as the port number. Publish on 127.0.0.1 when only this machine should reach the service, and leave the address out only when you mean every interface.

podman run -d --name pub -p 127.0.0.1:8014:8000 localhost/podman-app:dev
curl -s http://127.0.0.1:8014/health
podman port pub

Expected: curl prints {"status": "ok"}. podman port pub lists the container port 8000 and its host address and port, 127.0.0.1:8014.

Compare with a publish on all interfaces. Do this only on a machine you control:

podman rm -f pub
podman run -d --name pub -p 8014:8000 localhost/podman-app:dev
podman port pub
podman rm -f pub

Expected: the port is listed without an address, which means every interface of the host. On a laptop on a shared network, that exposes the service to other machines.

Low ports. Rootless containers cannot bind ports below 1024 by default, because that needs privilege on Linux. Trying it gives a permission error that mentions binding the port:

podman run -d --name low -p 127.0.0.1:80:8000 localhost/podman-app:dev
cat /proc/sys/net/ipv4/ip_unprivileged_port_start

Expected: the run fails with a permission error. The second command prints the first port a non-root process may bind. The default is 1024. The fix is to publish a higher host port, such as 8080. If you must publish a low port, lower the threshold with a system setting, and understand that it applies to every non-root process on the host:

sudo sysctl net.ipv4.ip_unprivileged_port_start=80
Lowering ip_unprivileged_port_start lets any user on the host bind those ports. On a shared host, publish a high port and put a reverse proxy in front.

Common errors.

  • address already in use: another process listens on that host port. Find it with ss -ltnp.
  • Published port unreachable from another machine: it is bound to 127.0.0.1. That is the intended setting. Change it only with a reason.

Production note. Publish one port per service where users need it, bind to the address the proxy uses, and document each published port in the runbook.

Pods

Hour 5 · 32–44 · 12 min

A pod is a group of containers that share some namespaces. Podman starts a small infrastructure container for the pod, which holds the shared namespaces. By default the containers in a pod share the network namespace, so they reach each other on localhost. They do not share their file systems.

pod "demo"  (infra container holds the network namespace)
  +-- demo-app   listens on 0.0.0.0:8000
  +-- demo-side  runs sleep, reaches the app on 127.0.0.1:8000

Create the pod, add two containers, and call the app from the sidecar:

podman pod create --name demo -p 127.0.0.1:8013:8000
podman run -d --pod demo --name demo-app localhost/podman-app:dev
podman run -d --pod demo --name demo-side docker.io/library/alpine:3.20 sleep 3600
podman run --rm --pod demo docker.io/library/alpine:3.20 wget -qO- http://127.0.0.1:8000/health
curl -s http://127.0.0.1:8013/health

Expected: the wget from a container in the pod prints {"status": "ok"}, because containers in the pod share localhost. The curl on the host also prints it, through the port published on the pod.

Inspect the pod and its containers:

podman pod ps
podman ps --pod
podman pod inspect demo

Expected: pod ps lists demo with its status and container count. ps --pod adds a pod column to each container.

Stop and remove the pod. Removing it removes its containers:

podman pod stop demo
podman pod rm -f demo
Port publishing belongs to the pod, not to each container, so the -p option is on pod create. A pod is also the unit Kubernetes uses. Hour 6 turns a pod into a Kubernetes manifest.

Common errors.

  • A container in the pod cannot reach another on its own name: containers in a pod share localhost, so use 127.0.0.1, not the name.
  • The port is not published: -p was given to a container inside the pod, not to pod create.

Production note. Put containers in a pod only when they must share an address and a lifecycle, such as an app and its log shipper. Separate services belong in separate pods on a user-defined network.

Connectivity troubleshooting

Hour 5 · 44–54 · 10 min

When two containers cannot reach each other, check in this order: are they on the same network, can they resolve each other's name, and does the port answer on the address the service really listens on.

Run the checks for the appnet case. Start the service and a test container on the same network:

podman network create appnet
podman run -d --name web --network appnet localhost/podman-app:dev
podman run --rm --network appnet docker.io/library/alpine:3.20 nslookup web
podman run --rm --network appnet docker.io/library/alpine:3.20 wget -qO- http://web:8000/health
podman network inspect appnet

Expected: nslookup prints an address for web. wget prints {"status": "ok"}. network inspect lists web. If nslookup fails, the containers are not on the same user-defined network.

Now check the address the service listens on. The sample listens on 0.0.0.0, which accepts connections from other containers. A service bound to 127.0.0.1 inside its container accepts only local connections. The check is in the application: HTTPServer(("0.0.0.0", PORT), ...) in app.py.

Clean up:

podman rm -f web
podman network rm appnet
Test with the same tool the application uses, and test the route that matters. A TCP connection that opens is not the same as a working health route.

Common errors.

  • nslookup: can't resolve 'web': different networks, or the container name is different from the name you used.
  • Connection refused on a working name: the service is not listening on that port, or it listens on loopback only.

Production note. Keep a short connectivity checklist in the runbook: network, name, port, route. The checks above take a minute and find most failures.

Production network layout

Hour 5 · 54–60 · 6 min

A production layout separates the parts of an application by how much they should be reachable:

LayerReachable fromExample
Public edgeusers, through a published port or a proxya reverse proxy on a published port
Application networkthe proxy and the services onlyorders-backend
Data networkthe services only, never the hostthe database

Create a data network with no route outside, which Podman supports with --internal:

podman network create --internal orders-data
podman network inspect orders-data

Expected: the network is created, and inspect shows it as internal. Containers on this network can reach each other but not the outside.

Clean up:

podman network rm orders-data
Do not use --network host to make a connection work. It removes the isolation of every container that uses it. Fix the network name or the listen address instead.

Production note. Publish the edge only. The application and data networks stay unpublished. Write down which port each service publishes, and why.

Cheat sheet

Hour 5 ·
TaskCommand
Show the rootless helperpodman info
Create a networkpodman network create NAME
Create an internal networkpodman network create --internal NAME
List networkspodman network ls
Inspect a networkpodman network inspect NAME
Run on a networkpodman run -d --network NAME --name NAME IMAGE
Publish on one addresspodman run -p 127.0.0.1:HOST:CONTAINER IMAGE
Show published portspodman port NAME
Create a pod with a published portpodman pod create --name NAME -p 127.0.0.1:HOST:CONTAINER
Run inside a podpodman run -d --pod NAME IMAGE
List podspodman pod ps
Containers with their podspodman ps --pod
Resolve a name from a networkpodman run --rm --network NAME IMAGE nslookup NAME

Capstone lab: a private service with one published edge

Hour 5 ·

Goal. Run the sample service on a private network with no published port, reach it from a second container, and prove the host cannot reach it.

podman network create appnet
podman rm -f web 2>/dev/null
podman run -d --name web --network appnet localhost/podman-app:dev
podman run --rm --network appnet docker.io/library/alpine:3.20 wget -qO- http://web:8000/health
curl -s --max-time 3 http://127.0.0.1:8000/health || echo "host cannot reach web: expected"
podman rm -f web
podman network rm appnet

Expected. The wget from the second container prints {"status": "ok"}. The curl from the host fails, and the echo runs, because nothing is published.

Verify. podman port web prints nothing once the container is running, since no port is published.

Clean up. The commands above remove the container and the network.

Final quiz

Hour 5

Sources and version notes