Skip to content

[JENKINS-72443] can not get container id if the Jenkins is running in a podman #713

Open

Description

@jenkins-infra-bot

when try to use docker.image(), it will find the container id first. However, the current method getContainerIdIfContainerized() can not parse the container id because the return message of /proc/1/moutninfo is different. Please refer to the following.

cat /proc/1/mountinfo | grep /hostname

1339 1333 0:48 /containers/overlay-containers/4c4d5c5475f78f2b8a98e2894adcc3152ac587ac3c406a5c4eb74cc3f129c03c/userdata/hostname /etc/hostname rw,nosuid,nodev,relatime - tmpfs tmpfs rw,seclabel,size=1609596k,mode=700,uid=1001,gid=1001

 

Reproduction steps

  1. run a docker container in a podman container, on REHL8.
  2. go to the docker conainer
  3. run command: cat /proc/1/mountinfo | grep /hostname
  4. check the string which contains the contianer id.

Expected Results

the current code uses regexp "/containers/([a-z0-9]{64})/hostname" to parse the container id, so it expects /containers/[id]/hostname.

Actual Results

1339 1333 0:48 /containers/overlay-containers/4c4d5c5475f78f2b8a98e2894adcc3152ac587ac3c406a5c4eb74cc3f129c03c/userdata/hostname /etc/hostname rw,nosuid,nodev,relatime - tmpfs tmpfs rw,seclabel,size=1609596k,mode=700,uid=1001,gid=1001


Originally reported by westmount, imported from: can not get container id if the Jenkins is running in a podman
  • assignee: naveenboni
  • status: Open
  • priority: Blocker
  • component(s): docker-workflow-plugin
  • resolution: Unresolved
  • votes: 0
  • watchers: 5
  • imported: 2025-12-07
Raw content of original issue

when try to use docker.image(), it will find the container id first. However, the current method getContainerIdIfContainerized() can not parse the container id because the return message of /proc/1/moutninfo is different. Please refer to the following.

cat /proc/1/mountinfo | grep /hostname

1339 1333 0:48 /containers/overlay-containers/4c4d5c5475f78f2b8a98e2894adcc3152ac587ac3c406a5c4eb74cc3f129c03c/userdata/hostname /etc/hostname rw,nosuid,nodev,relatime - tmpfs tmpfs rw,seclabel,size=1609596k,mode=700,uid=1001,gid=1001

 

Reproduction steps

  1. run a docker container in a podman container, on REHL8.
  2. go to the docker conainer
  3. run command: cat /proc/1/mountinfo | grep /hostname
  4. check the string which contains the contianer id.

Expected Results

the current code uses regexp "/containers/([a-z0-9]{64})/hostname" to parse the container id, so it expects /containers/[id]/hostname.

Actual Results

1339 1333 0:48 /containers/overlay-containers/4c4d5c5475f78f2b8a98e2894adcc3152ac587ac3c406a5c4eb74cc3f129c03c/userdata/hostname /etc/hostname rw,nosuid,nodev,relatime - tmpfs tmpfs rw,seclabel,size=1609596k,mode=700,uid=1001,gid=1001

environment
REHL8,<br/>
&nbsp;Jenkins running in podman on REHL8, docker installed in Jenkins image

Activity

  1. jenkins-infra-bot commented on Dec 20, 2023

    @jenkins-infra-bot
    Author
    westmount:
    • Comment link
    • Original comment link (no redirect)
    • Raw content of original comment:

      I think it will wok if we replace the regex hostnameMount "/containers/([a-z0-9] in file DockerClient.java.

       private static final Pattern hostnameMount = Pattern.compile("containers/([a-z0-9]{64})/*\\w*/hostname");
       

    I think it will wok if we replace the regex hostnameMount "/containers/([a-z0-9] in file DockerClient.java.

     private static final Pattern hostnameMount = Pattern.compile("containers/([a-z0-9]{64})/*\\w*/hostname");
     
  2. jenkins-infra-bot commented on Jan 9, 2024

    @jenkins-infra-bot
    Author
    romaingeissler1a:
    • Comment link
    • Original comment link (no redirect)
    • Raw content of original comment:

      Hi,

      The above mentioned regular expression doesn't work (at least with sed).

      This seems to work no matter if the host uses cgroup v1 or v2, and the container engine is docker or podman:

      [root@783f0a980788 /]# cat /proc/self/mountinfo | sed -n '/ \/etc\/hostname /{s/.*\/\([a-f0-9]\{64,\}\)\/.*/\1/;p}'
      783f0a980788c840ed872d982c574e30ce006494837c617acb2a168dae406bc2 

      Which would be translated a bit different if the regex matching is done in pure java.

    Hi,

    The above mentioned regular expression doesn't work (at least with sed).

    This seems to work no matter if the host uses cgroup v1 or v2, and the container engine is docker or podman:

    [root@​783f0a980788 /]# cat /proc/self/mountinfo | sed -n '/ \/etc\/hostname /{s/.*\/\([a-f0-9]\{64,\}\)\/.*/\1/;p}'
    783f0a980788c840ed872d982c574e30ce006494837c617acb2a168dae406bc2 

    Which would be translated a bit different if the regex matching is done in pure java.

  3. jenkins-infra-bot commented on May 17, 2024

    @jenkins-infra-bot
    Author
    jeannette9728miller:
    • Comment link
    • Original comment link (no redirect)
    • Raw content of original comment:

      The issue lies in how Podman structures its container filesystems compared to Docker, which affects how Jenkins' Docker workflow plugin parses container IDs. Specifically, the regular expression used (/containers/([a-z0-9]

      {64}

      )/hostname) to identify the container ID from /proc/1/mountinfo does not match the Podman container filesystem path (/containers/overlay-containers/...).

      Update the regular expression used in Jenkins' Docker workflow plugin to correctly parse the container ID from the Podman environment. You may need to adjust it to match the actual path structure used by Podman.

      If the plugin's regular expression cannot be easily modified, consider writing a custom script or plugin extension specifically for Podman environments. This script would correctly parse the container ID from /proc/1/mountinfo based on Podman's filesystem layout.

      Check for updates or patches to the Docker workflow plugin that may address compatibility with Podman. Sometimes, plugin updates include fixes or enhancements for different container runtimes.

      As a temporary workaround, manually inspect /proc/1/mountinfo on your Podman host to understand its structure and identify the correct path or pattern to extract the container ID. This can help in adjusting the regular expression or writing a custom solution.

    The issue lies in how Podman structures its container filesystems compared to Docker, which affects how Jenkins' Docker workflow plugin parses container IDs. Specifically, the regular expression used (/containers/([a-z0-9]

    {64}

    )/hostname) to identify the container ID from /proc/1/mountinfo does not match the Podman container filesystem path (/containers/overlay-containers/...).

    Update the regular expression used in Jenkins' Docker workflow plugin to correctly parse the container ID from the Podman environment. You may need to adjust it to match the actual path structure used by Podman.

    If the plugin's regular expression cannot be easily modified, consider writing a custom script or plugin extension specifically for Podman environments. This script would correctly parse the container ID from /proc/1/mountinfo based on Podman's filesystem layout.

    Check for updates or patches to the Docker workflow plugin that may address compatibility with Podman. Sometimes, plugin updates include fixes or enhancements for different container runtimes.

    As a temporary workaround, manually inspect /proc/1/mountinfo on your Podman host to understand its structure and identify the correct path or pattern to extract the container ID. This can help in adjusting the regular expression or writing a custom solution.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions