6

I follow a podman tutorial,which shows multi containers interacting in same network.

$ podman network create foo
/home/user/.config/cni/net.d/foo.conflist
$ podman run -d --name web --hostname web --network foo nginx:alpine
$ podman run --rm --network foo alpine wget -O - http://web.dns.podman

The expected result is

Connecting to web.dns.podman (10.88.4.6:80)
...
<h1>Welcome to nginx!</h1>
...

But I got

wget: bad address 'web.dns.podman'

I guess container network dns fail,But container can resolve other network domain like www.baidu.com normally,it just cannot resolve container name.I have no idea how to fix it.

asked Apr 8, 2022 at 2:39

4 Answers 4

2

PreRequirements:

First you have to install podman-plugins & containernetworking-plugins using this command:

$ sudo dnf -y install podman-plugins containernetworking-plugins

It's required to run this command before network creation. If you already created your network, consider creating a fresh network after installing the packages. rt the system after installation.

Unix Domain Sockets:

***This is the best option I ever tried.***

As an stable and reliable option you can use Unix Domain Sockets and share them through named volumes.

Don't forget to use volumes with this flags to be writeable by container: "rw,z".

The TCP Solution:

Then you should be able to communicate inter-container using container names.

Same Pod

If they are in the same pod, it's enough to call the container alias, Like:

$ podman network create foo
$ podman pod create --name=ptestpod
$ podman run -d --name web1 --pod=testpod --network foo nginx:alpine
$ podman run -d --name web2 --pod=testpod --network foo nginx:alpine

In the web1 container you can simply ping web2 and vise versa, It's working.

Different Pod

If they are not in the same pod but same network, the full name will work. For Example:

$ podman network create foo
$ podman pod create --name=testpod1
$ podman run -d --name web1 --pod=testpod1 --network foo nginx:alpine
$ podman pod create --name=testpod2
$ podman run -d --name web2 --pod=testpod2 --network foo nginx:alpine

In this case you should just use fullname. In the web1 container you can ping testpod2_web2_1 and it works!

Notice:

  • If you are not using pods the second case will work everywhere.
  • It's not a problem for containers to register on multiple networks. But the containers must have at least one common network.
  • It's important to keep just one network DNS enabled. If more than one network with enabled dns is connected to container it will fail to resolve anything.
answered Jan 31, 2023 at 10:12
Sign up to request clarification or add additional context in comments.

9 Comments

Why add the '_1' at the end in the second case? Also it seems to work intermittently. I run the example you gave and do 100 times the command podman exec -it web1 sh -c 'ping -c 1 web2' and get about a 5 failures with the error: ping: bad address 'web2'
The ping bad address is an issue in podman default network and I'm still working to find a solution for it. But it works most of the time. _1 is the number of same container services in the pod for scalability.
If you want a stable networking in podman change network backends to cni and it works like a charm
I tried both CNI and Netvark and see the same flaky, intermittent issue.
At the latest versions netavark is more stable, but as i said use unix domains in named volume. Simpler and more performant.
|
1

Did you find a solution? This problem is preventing me form using podman-compose.

My setting is:

  • Podman v 4.3.0
  • Arch Linux, kernel 6.0.7
  • slirp4netns (v 2.5.4) installed

The communication within a pod works as expected, but across containers from different pods, the hostname do net get resolved.

answered Nov 10, 2022 at 10:01

Comments

1

In the meantime, I found out, what my problem was. I don't know, if it helps in your case.

On my machine, the package podman-dnsname (install it from here or from the package respository of your distro) was missing.

answered Nov 15, 2022 at 21:48

Comments

0

Install dependencies:

sudo apt-get install netavark aardvark-dns

Change configurations:

file /etc/containers/containers.conf

[network]
network_backend = "netavark"

Now after creating the network you see with podman network inspect foo:

[ 
 { 
 "name": "foo",
 "id": "79a41794b5cb811d8d5c6a11f8285d9c21abed9e5fe7014d70c18b0a2345dd97",
 "driver": "bridge", 
 "network_interface": "podman1", 
 "created": "2025年01月13日T16:08:42.807457441+01:00",
 "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" 
 } 
 }
] 

And it should work.

answered Jan 13, 2025 at 15:20

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.