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

Container command '/bin/cat' not found or does not exist

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Critical Critical
    • None
    • docker:1.11
      jenkins:1.651.2
      docker-custom-build-environment:1.6.5

      I'm using Jenkins as a Docker container by installing Docker within my Jenkins container and binding Docker socket (see config below).
      I try to compile a Maven project using maven:3.2-jdk-7 (see attached image).
      But I have this error:

      $ docker run --rm --entrypoint /bin/true alpine:3.2
      $ docker run --tty --rm --entrypoint /sbin/ip alpine:3.2 route
      $ docker run --tty --detach --workdir /var/jenkins_home/jobs/xxxxx/workspace --volume /var/jenkins_home:/var/jenkins_home:rw --volume /tmp:/tmp:rw --net bridge --add-host dockerhost:172.17.0.1 --env BUILD_DISPLAY_NAME=#1 --env BUILD_ID=1 --env BUILD_NUMBER=1 --env BUILD_TAG=xxxxx-1 --env BUILD_URL=http://localhost:8080/job/xxxxx/1/ --env CLASSPATH= --env EXECUTOR_NUMBER=0 --env GIT_BRANCH=origin/master --env GIT_COMMIT=883d20d67b50b0daea5a78d3192a4f84ed282fb4 --env GIT_URL=https://git.xxxxxxxx.git --env HUDSON_HOME=/var/jenkins_home --env HUDSON_SERVER_COOKIE=70042bb5dbdea6c1 --env HUDSON_URL=http://localhost:8080/ --env JENKINS_SERVER_COOKIE=70042bb5dbdea6c1 --env JENKINS_URL=http://localhost:8080/ --env JOB_NAME=xxxxx --env JOB_URL=http://localhost:8080/job/xxxxx/ --env NODE_LABELS=master --env NODE_NAME=master --env WORKSPACE=/var/jenkins_home/jobs/xxxxx/workspace maven:3.2-jdk-7 /bin/cat
      docker: Error response from daemon: Container command '/bin/cat' not found or does not exist..
      FATAL: Failed to run docker image
      java.lang.RuntimeException: Failed to run docker image
      	at com.cloudbees.jenkins.plugins.docker_build_env.Docker.runDetached(Docker.java:226)
      	at com.cloudbees.jenkins.plugins.docker_build_env.DockerBuildWrapper.startBuildContainer(DockerBuildWrapper.java:202)
      	at com.cloudbees.jenkins.plugins.docker_build_env.DockerBuildWrapper.setUp(DockerBuildWrapper.java:175)
      	at hudson.model.Build$BuildExecution.doRun(Build.java:156)
      	at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:534)
      	at hudson.model.Run.execute(Run.java:1738)
      	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
      	at hudson.model.ResourceController.execute(ResourceController.java:98)
      	at hudson.model.Executor.run(Executor.java:410)
      Finished: FAILURE
      

      I don't understand why I have this error as I'm able to compile my project locally using this Maven Docker image.

      Here is my config:

      Dockerfile

      FROM jenkins:1.651.2
      
      USER root
      
      RUN \
        apt-get update && \
        apt-get install -y apt-transport-https ca-certificates && \
        echo "deb https://apt.dockerproject.org/repo debian-jessie main" > /etc/apt/sources.list.d/docker.list && \
        apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D && \
        apt-get update && \
        apt-get install -y \
          lxc \
          sudo \
          docker-engine \
          bzip2 && \
        usermod -a -G docker jenkins
      
      RUN chown -R jenkins "$JENKINS_HOME" /usr/share/jenkins/ref
      
      USER jenkins
      

      docker-compose.yml

      jenkins:
        build: .
        ports:
          - "8080:8080"
          - "5000:5000"
        volumes:
          - /var/run/docker.sock:/var/run/docker.sock
      

          [JENKINS-35025] Container command '/bin/cat' not found or does not exist

          Wills Ward added a comment -

          If you remove the `--workdir` argument, the docker will launch properly. I'm not sure why though.

          Wills Ward added a comment - If you remove the `--workdir` argument, the docker will launch properly. I'm not sure why though.

          David Chua added a comment -

          I'm also having the same problem.

          I'm running jenkins inside of a docker image.

          ```
          docker run --user root -p 8080:8080 -p 50000:50000 -v /home/user/jenkins_home:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock jenkins:latest
          ```

          The user above mentioned something about --workdir, could it be because the docker command that jenkins is using calls the docker daemon of the host, and its attempting to access a --workdir that doesn't exist as it is located inside of the jenkins container.

          Is there a workaround this?

          David Chua added a comment - I'm also having the same problem. I'm running jenkins inside of a docker image. ``` docker run --user root -p 8080:8080 -p 50000:50000 -v /home/user/jenkins_home:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock jenkins:latest ``` The user above mentioned something about --workdir, could it be because the docker command that jenkins is using calls the docker daemon of the host, and its attempting to access a --workdir that doesn't exist as it is located inside of the jenkins container. Is there a workaround this?

          Wills Ward added a comment -

          davidchua That's just the thing. The directory does exist in the container because of the volume mount. In addition, workdir should create the dir if it doesn't exisit.

          Here's a relevant github issue.

          I haven't found a workaround.

          Wills Ward added a comment - davidchua That's just the thing. The directory does exist in the container because of the volume mount. In addition, workdir should create the dir if it doesn't exisit. Here's a relevant github issue . I haven't found a workaround.

          David Chua added a comment - - edited

          willseward In a way, isn't the github issue the exact opposite? In our case here, as you mentioned, removing the workdir would work but in the github issue, adding the workdir will fix the missing /bin/bash problem.

          I wonder what's going on.

          I'm using the docker-custom-build-environment plugin - https://wiki.jenkins-ci.org/display/JENKINS/CloudBees+Docker+Custom+Build+Environment+Plugin which runs the docker command with workdir and it doesn't look like there's anyway to customize the run arguments.

          David Chua added a comment - - edited willseward In a way, isn't the github issue the exact opposite? In our case here, as you mentioned, removing the workdir would work but in the github issue, adding the workdir will fix the missing /bin/bash problem. I wonder what's going on. I'm using the docker-custom-build-environment plugin - https://wiki.jenkins-ci.org/display/JENKINS/CloudBees+Docker+Custom+Build+Environment+Plugin which runs the docker command with workdir and it doesn't look like there's anyway to customize the run arguments.

          Wills Ward added a comment -

          davidchua I noticed that too.

          Have you tried copying the build command directly into the cli on a build server to see if the workdir is your problem too?

          Wills Ward added a comment - davidchua I noticed that too. Have you tried copying the build command directly into the cli on a build server to see if the workdir is your problem too?

          Adam Cleankod added a comment -

          Did anyone find a solution to this problem? I'm having the same issue and executing the command directly does not have this issue.

          Adam Cleankod added a comment - Did anyone find a solution to this problem? I'm having the same issue and executing the command directly does not have this issue.

          Alex Milstead added a comment - - edited

          I'm not 100% sure why this is happening, but I had the same issue and was able to work around it by modifying my entrypoint.

          I changed it to:

          ENTRYPOINT ["/bin/bash", "-c"]
          

          It might have something to do with the other options going into the run command? Not totally positive. Either way, using "-c" accepts the command (i.e. /bin/cat) as text to execute in the context of a shell, rather than whatever it's doing without that.

          Alex Milstead added a comment - - edited I'm not 100% sure why this is happening, but I had the same issue and was able to work around it by modifying my entrypoint. I changed it to: ENTRYPOINT [ "/bin/bash" , "-c" ] It might have something to do with the other options going into the run command? Not totally positive. Either way, using "-c" accepts the command (i.e. /bin/cat) as text to execute in the context of a shell, rather than whatever it's doing without that.

          Alex Milstead added a comment -

          To be clear: I was able to control the Dockerfile definition of the image being run for the build.

          Alex Milstead added a comment - To be clear: I was able to control the Dockerfile definition of the image being run for the build.

          sachin gupta added a comment -

          is there any resolution to this issue, we are also facing the same issue even in Jenkins version 2.161

          sachin gupta added a comment - is there any resolution to this issue, we are also facing the same issue even in Jenkins version 2.161

            Unassigned Unassigned
            cthiebault Cedric Thiebault
            Votes:
            3 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated: