How to pass docker container arguments when running the image in a Jenkinsfile
Use .withRun('-p 3000:3000', '--arg1 arg1 --arg2 arg2')
. The documentation for this is in the docker-workflow-plugin here.
You can use the second argument of withRun
.withRun('-p 3000:3000', '--arg1 somearg --arg2 anotherarg')
I leave this post because it was asked in a comment above: The documentation for Docker Pipeline plugin can be accessed like this:
- Go to any Pipeline Job, and on the bottom click on the link [Pipeline Syntax]
- One the left menu choose Global variable Reference. The plugin has the docker variable (with supported methods)
Another way you pass container arguments is by using the inside method. Below is an example taken from https://jenkins.io/doc/book/pipeline/docker/#caching-data-for-containers (click on the Toggle Scripted Pipeline link to view it)
node {
/* Requires the Docker Pipeline plugin to be installed */
docker.image('maven:3-alpine').inside('-v $HOME/.m2:/root/.m2') {
stage('Build') {
sh 'mvn -B'
}
}
}