Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-72443

can not get container id if the Jenkins is running in a podman

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Blocker Blocker
    • docker-workflow-plugin
    • None
    • REHL8,
       Jenkins running in podman on REHL8, docker installed in Jenkins image

      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

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

          Braden added a comment - - edited

          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");
           

          Braden added a comment - - edited 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" );

          Romain Geissler added a comment - - edited

          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.

          Romain Geissler added a comment - - edited 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.

          jeannette added a comment - - edited

          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.

          jeannette added a comment - - edited 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.

            naveenboni Naveen Boni
            westmount Braden
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: