Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hostname points to the name of the infra container instead to hostname of the pod itself #11

abalage opened this issue Jan 29, 2020 · 9 comments


Copy link

@abalage abalage commented Jan 29, 2020


I am having an issue with name resolution not working with pod names.
I would like to achieve pod-to-pod communication via hostnames / DNS of pods.

I create a pod for each different systems I may use. Each pods contain different number of containers. The plugin dnsname is configured for the default network.

The very basic setup I'd like to achieve can be seen on the picture below.


As all the pods are attached to the same network (cni-podman0) IP connectivity is not a problem.
Checking the hosts file within containers of the same pod I see that they aware of the hostname of the pod as well its IP address.
However the DNS service running in the same network is only resolving the IP addresses of infra containers. The problem with that is their name is auto generated from the ID of the pod. I cannot rely on them. I would rather like to see the --name or --hostname of the pods bounded to the IP of infra contrainer by dnsname.

Checking the source code I could find this part.

type podname struct {
K8S_POD_NAME types.UnmarshallableString `json:"podname,omitempty"`

But I do not know whether 'podname' should point to the name of the pod (sounds reasonable) of to the name of the container?

# podman network inspect podman
                "cniVersion": "0.4.0",
                "name": "podman",
                "plugins": [
                                "bridge": "cni-podman0",
                                "ipMasq": true,
                                "ipam": {
                                        "ranges": [
                                                                "gateway": "",
                                                                "subnet": ""
                                        "routes": [
                                                        "dst": ""
                                        "type": "host-local"
                                "isGateway": true,
                                "type": "bridge"
                                "domainName": "podman.local",
                                "type": "dnsname"
                                "capabilities": {
                                        "portMappings": true
                                "type": "portmap"
                                "backend": "firewalld",
                                "type": "firewall"

# podman ps -ap
CONTAINER ID  IMAGE                                                COMMAND               CREATED      STATUS          PORTS                                                   NAMES               POD           POD NAME
bc79e85d737f                         nginx -g daemon o...  3 hours ago  Up 3 hours ago>80/tcp                              proxy               e59ccfa83aa6  reverse_proxy
f89ad7e8e4cd                                      3 hours ago  Up 3 hours ago>80/tcp                              e59ccfa83aa6-infra  e59ccfa83aa6  reverse_proxy
29b35a360e91                       mysqld                3 hours ago  Up 3 hours ago>3306/tcp                                  mariadb             c7090bdc990d  mysql
32e01f41626a                                      3 hours ago  Up 3 hours ago>3306/tcp                                  c7090bdc990d-infra  c7090bdc990d  mysql
048bb0b9fe83                            redis-server          3 hours ago  Up 3 hours ago>80/tcp                                    nextcloud-redis     fe69e1d9a88e  nextcloud
70cc7e3d0bb3                         nginx -g daemon o...  3 hours ago  Up 3 hours ago>80/tcp                                    nextcloud-www       fe69e1d9a88e  nextcloud
ebc69be64be9  localhost/balage/php72-fpm-opensuse:latest           php-fpm -c /etc/p...  3 hours ago  Up 3 hours ago>80/tcp                                    nextcloud-php       fe69e1d9a88e  nextcloud
fbdd9fa5baad                                      3 hours ago  Up 3 hours ago>80/tcp                                    fe69e1d9a88e-infra  fe69e1d9a88e  nextcloud
b27d58d62133                /usr/local/bin/ki...  3 hours ago  Up 3 hours ago>5601/tcp,>9200/tcp  kibana              03e5e1a02d0f  elk
db3a7c79d3bf  eswrapper             3 hours ago  Up 3 hours ago>5601/tcp,>9200/tcp  elasticsearch       03e5e1a02d0f  elk

# cat /run/containers/cni/dnsname/podman/addnhosts     03e5e1a02d0f-infra     fe69e1d9a88e-infra     c7090bdc990d-infra     e59ccfa83aa6-infra

# podman exec -ti nextcloud-www cat /etc/hosts       localhost
...     nextcloud

Here are some details you may find useful.

# podman --version
podman version 1.7.0

# podman info 
  BuildahVersion: 1.12.0
  CgroupVersion: v1
    package: conmon-2.0.9-lp151.19.1.x86_64
    path: /usr/bin/conmon
    version: 'conmon version 2.0.9, commit: unknown'
    distribution: '"opensuse-leap"'
    version: "15.1"
  MemFree: 4509601792
  MemTotal: 8340729856
    name: runc
    package: runc-1.0.0~rc6-lp151.1.2.x86_64
    path: /usr/sbin/runc
    version: |-
      runc version 1.0.0-rc6
      spec: 1.0.1-dev
  SwapFree: 0
  SwapTotal: 0
  arch: amd64
  cpus: 2
  eventlogger: file
  hostname: linux-thwt
  kernel: 5.4.14-1.gfc4ea7a-default
  os: linux
  rootless: false
  uptime: 3h 45m 32.16s (Approximately 0.12 days)
  ConfigFile: /etc/containers/storage.conf
    number: 11
  GraphDriverName: overlay
  GraphOptions: {}
  GraphRoot: /var/lib/containers/storage
    Backing Filesystem: extfs
    Native Overlay Diff: "true"
    Supports d_type: "true"
    Using metacopy: "false"
    number: 9
  RunRoot: /var/run/containers/storage
  VolumePath: /var/lib/containers/storage/volumes
Copy link

@abalage abalage commented Jan 29, 2020


I would need a 'poor man's' service discovery. Find published ports of pods on the same network by using the name of the pods. And not by the name of the infra container of a pod.

Copy link

@baude baude commented Jan 29, 2020

@abalage name resolution does is not supported yet for pods ... BUT I am currently working on it

Copy link

@abalage abalage commented Jan 29, 2020

Great to hear. I am happy to test any release you may have.

Copy link

@ecks ecks commented Feb 19, 2020

I would be interested in this feature as well, since I would like to use "podman play kube" as a way to import podman configurations. When you do that, everything gets imported as a pod, so my workaround has been to manually add the container name entries to addnhosts file.

Would this be the correct place to track the progress?

Copy link

@mi-hol mi-hol commented Jul 13, 2020

@baude any news re 'currently working on it'?

Copy link

@baude baude commented Jul 16, 2020

@mi-hol sorry! yes, name resolution for pods works like containers now. Remember all containers in a podman pod share the same network namespace by default. So you can set the hostname with podman pod create --hostname.

Copy link

@mi-hol mi-hol commented Jul 21, 2020

@baude , would your answer mean that this issue should be closed?

Copy link

@baude baude commented Aug 3, 2020

I think so but always nice that the reported concurs... closing. Please re-open or open a new issue if you disagree.

@baude baude closed this as completed Aug 3, 2020
Copy link

@WolfangAukang WolfangAukang commented Sep 17, 2020

Hello @baude, so a quick question about using this feature. I am running the following:

podman pod create --name pod_db --network foobar --hostname db
podman run -d --pod pod_db --name mariadb -e MYSQL_RANDOM_ROOT_PASSWORD=1 mariadb:10.4
podman pod create --name pod_front --network foobar --hostname frontend
podman run -it --pod pod_front busybox sh

foobar is a network created according to the guide and it runs as expected between pods. But if I try to run ping db or telnet db 3306, it does not get any answers. Am I doing something wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

No branches or pull requests

5 participants