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

cat command in docker agents not detected correctly

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Reopened (View Workflow)
    • Priority: Minor
    • Resolution: Unresolved
    • Component/s: docker-workflow-plugin
    • Labels:
      None
    • Environment:
      Jenkins 2.104 on Docker 17.10.0-ce on CentOS 7.4.1708 (Kernel 3.10.0-693.2.2.el7.x86_64)
    • Similar Issues:

      Description

      When using a declarative Jenkins pipeline with a stage that uses a Docker agent, I get a confusing error message in the Jenkins log:

      $ docker top 08e1c013e07083492ad0f03285f1a7d30063fb15e0cf39be7b55af6d1a03c829
      ERROR: The container started but didn't run the expected command. Please double check your ENTRYPOINT does execute the command passed as docker run argument. See https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/#entrypoint for entrypoint best practices.
      

      The build continues normally and the cat command is actually running inside the container, so everything is fine except that the error message occurs although it shouldn't.

      Comparing the code in listProcess in https://github.com/jenkinsci/docker-workflow-plugin/blob/master/src/main/java/org/jenkinsci/plugins/docker/workflow/client/DockerClient.java with the output of docker top shows the likely cause of that error:

      docker top prints the following fields

      UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
      build               19799               19784               0                   22:23               pts/0               00:00:00            cat
      

      However, the Java client assumes that only PID, USER, TIME and COMMAND is printed. I suggest that the process list is determined by using an explicit format specifier like

      docker container top ${CONTAINER_ID} -eo pid,comm
      

        Attachments

          Issue Links

            Activity

            Hide
            sachin771 sachin gupta added a comment -

            Hello Chisel Wright,

            can you share the complete name of the plugin, Sorry I'm new to Jenkins and docker and just performing some poc for learning perspectives.

            Show
            sachin771 sachin gupta added a comment - Hello Chisel Wright , can you share the complete name of the plugin, Sorry I'm new to Jenkins and docker and just performing some poc for learning perspectives.
            Hide
            chizcw Chisel Wright added a comment -
            Show
            chizcw Chisel Wright added a comment - It's this one:  https://plugins.jenkins.io/docker-workflow
            Hide
            sachin771 sachin gupta added a comment -

            Thanks Chisel Wright,

            I had just downgraded the same plugin before your reply and my builds worked fine.

            Show
            sachin771 sachin gupta added a comment - Thanks Chisel Wright , I had just downgraded the same plugin before your reply and my builds worked fine.
            Hide
            andrewnicols Andrew Nicols added a comment -

            I suspect that this is the same as JENKINS-54389, and also JENKINS-39748.

            Any longer-running entrypoint will cause the job to fail because the cat command doesn't run until the end of the entrypoint.

            Additionally, requiring an image to run cat could break the image. For example, if I wish to start an image whose CMD is apache-foreground then I expect apache to be running, not cat. I'm not going to serve any web responses with cat.

            I think the docker-workflow plugin either needs to:

            1. respect HEALTHCHECKs
            2. allow for either no CMD override, or a specified CMD override to be provided when running the image
            3. allow for a wait period before checking that the expected command is running

            Basically, don't run cat by default, instead respect the healthcheck.

            Show
            andrewnicols Andrew Nicols added a comment - I suspect that this is the same as JENKINS-54389 , and also JENKINS-39748 . Any longer-running entrypoint will cause the job to fail because the cat command doesn't run until the end of the entrypoint. Additionally, requiring an image to run cat could break the image. For example, if I wish to start an image whose CMD is apache-foreground then I expect apache to be running, not cat . I'm not going to serve any web responses with cat . I think the docker-workflow plugin either needs to: respect HEALTHCHECKs allow for either no CMD override, or a specified CMD override to be provided when running the image allow for a wait period before checking that the expected command is running Basically, don't run cat by default, instead respect the healthcheck.
            Hide
            jglick Jesse Glick added a comment -

            Any further behavioral changes in this area are likely to be incompatible and unlikely to be entertained. withDockerContainer was designed for “tool-only” images with no particular designated entrypoint (typically falling back to bash or something), since its entire purpose is to provide a passive container—basically a predefined filesystem layout—in which you can run sh steps. Images which expect to be running a specific process like Apache are not supported. You can use withRun, or (better) just run whatever docker commands you like directly.

            Show
            jglick Jesse Glick added a comment - Any further behavioral changes in this area are likely to be incompatible and unlikely to be entertained. withDockerContainer was designed for “tool-only” images with no particular designated entrypoint (typically falling back to bash or something), since its entire purpose is to provide a passive container—basically a predefined filesystem layout—in which you can run sh steps. Images which expect to be running a specific process like Apache are not supported. You can use withRun , or (better) just run whatever docker commands you like directly.

              People

              • Assignee:
                ndeloof Nicolas De Loof
                Reporter:
                hendrikhalkow Hendrik Halkow
              • Votes:
                1 Vote for this issue
                Watchers:
                31 Start watching this issue

                Dates

                • Created:
                  Updated: