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.
3
Answers
Did you find a solution? This problem is preventing me form using
podman-compose
.My setting is:
slirp4netns
(v 2.5.4) installedThe communication within a pod works as expected, but across containers from different pods, the hostname do net get resolved.
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.PreRequirements:
First you have to install
podman-plugins & containernetworking-plugins
using this command: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".
CNI Network:
Podman changed the default network stack to Netavark. it has some bugs and not working rill version 4.2.0 in rocky linux! newer versions wont compile due to glibc version.
It’s recommended to change your default network stack to CNI and recreate all networks with that.
It works in all ways! I checked everything and there is no bugs and it’s incredibly faster.
Just copy the config file:
Then in the file change the network backend to cni using the following command:
Notice: I think it’s better to restart you system in order to apply changes.
The 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:
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:
In this case you should just use fullname. In the web1 container you can
ping testpod2_web2_1
and it works!Notice: