skip to Main Content

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


  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.

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
  3. 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".

    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:

    sudo cp /usr/share/containers/containers.conf /etc/containers/containers.conf
    

    Then in the file change the network backend to cni using the following command:

    sed -i "/^s*#*s*network_backends*=.*$/ s/^.*$/network_backend = "cni"/" /etc/containers/containers.conf
    

    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:

    $ 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.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search