在Jenkinsfile中运行映像时如何传递Docker容器参数 [英] How to pass docker container arguments when running the image in a Jenkinsfile
问题描述
我有一个以结尾的Dockerfile
I have a Dockerfile that ends with
ENTRYPOINT ["node", "index.js"]
CMD ["--help"]
index.js
可以采用几个不同的参数,而且我还需要公开容器的端口,因此,如果我手动运行它,我会执行以下操作:
The index.js
can take a couple different arguments and I also need to expose a port for the container so if I run it manually I do something like:
docker run -p 3000:3000 my_container:latest --arg1 somearg --arg2 anotherarg
如何在Jenkinsfile中执行此操作?我的测试将与此容器通信,因此它需要在运行测试之前运行.我使用withRun()
使其在测试运行之前运行,但是我看不到如何指定--arg1 somearg --arg2 anotherarg
How do I do this in a Jenkinsfile? My test will communicate with this container so it needs to be running before I run the test. I use withRun()
get it running before the test runs but I don't see how to specify the --arg1 somearg --arg2 anotherarg
stage('TestMicroservice') {
//
// HOW DO I SPECIFY '--arg1 somearg --arg2 anotherarg'?
//
docker.image("my_container:latest").withRun('-p 3000:3000') {
sh 'npm run test-microservice'
}
}
推荐答案
您可以使用withRun的第二个参数
You can use the second argument of withRun
.withRun('-p 3000:3000', '--arg1 somearg --arg2 anotherarg')
这篇关于在Jenkinsfile中运行映像时如何传递Docker容器参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!