Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins docker container always adds cat command

I am creating Jenkins pipeline for running terraform on a Docker container.

Here is my pipeline script.

pipeline {
    agent {
        docker {
            image 'hashicorp/terraform:full'
            args '--entrypoint=/bin/bash'
        }
    }
    stages {
        stage('execute') { 
            steps {
                sh 'terraform --version' 
            }
        }
    }
}

When running this pipeline on Jenkins, I get the below error.

$ docker run -t -d -u 995:993 --entrypoint=/bin/bash -w /var/lib/jenkins/workspace/terraform -v /var/lib/jenkins/workspace/terraform:/var/lib/jenkins/workspace/terraform:rw,z -v /var/lib/jenkins/workspace/terraform@tmp:/var/lib/jenkins/workspace/terraform@tmp:rw,z -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** hashicorp/terraform:full cat

$ docker top a0b801d657d0fffdfa95c387564128b130ab1d28569ad59bd0151c8b7faf6ffd -eo pid,comm

java.io.IOException: Failed to run top 'a0b801d657d0fffdfa95c387564128b130ab1d28569ad59bd0151c8b7faf6ffd'. Error: Error response from daemon: Container a0b801d657d0fffdfa95c387564128b130ab1d28569ad59bd0151c8b7faf6ffd is not running

This seems like Jenkins add a cat command to run the image hashicorp/terraform:full.

Note that, I have overridden the entrypoint to /bin/bash using --entrypoint=/bin/bash since hashicorp/terraform:full already has an entrypoint defined.

like image 679
Param Avatar asked Mar 27 '19 04:03

Param


People also ask

How do you stop the container in detached mode?

To stop this container, press Ctrl+C in the terminal where it was started. Alternatively, you may start a container in detached mode using the -d option. To see all running containers, use the docker ps command.

How does Jenkins Dockerize applications?

To achieve this, we need a few Jenkins plugins installed. In Manage Jenkins , select Manage Plugins under System Configurations , search and install the following plugins: docker-build-step. CloudBees Docker Build and Publish.


1 Answers

I had to change the ENTRYPOINT to empty to disable the entrypoint definition from the terraform container definition. And I think the light image is sufficient for just executing terraform.

I got it working with the following script:

pipeline {
  agent {
    docker {
        image 'hashicorp/terraform:light'
        args '--entrypoint='
    }
  }
  stages {
    stage('execute') { 
        steps {
            sh 'terraform --version' 
        }
    }
  }
}
like image 85
S.Spieker Avatar answered Sep 17 '22 17:09

S.Spieker