我有一个以
结尾的DockerfileENTRYPOINT ["node", "index.js"]
CMD ["--help"]
index.js
可以使用几个不同的参数,我还需要为容器公开一个端口,所以如果我手动运行它,我会做类似的事情:
docker run -p 3000:3000 my_container:latest --arg1 somearg --arg2 anotherarg
如何在Jenkins文件中执行此操作?我的测试将与此容器通信,因此在运行测试之前需要运行它。我在测试运行之前使用withRun()
让它运行但我不知道如何指定--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'
}
}
答案 0 :(得分:4)
您可以使用withRun的第二个参数
.withRun('-p 3000:3000', '--arg1 somearg --arg2 anotherarg')
答案 1 :(得分:1)
使用.withRun('-p 3000:3000', '--arg1 arg1 --arg2 arg2')
。有关此文档,请参见docker-workflow-plugin here。
答案 2 :(得分:1)
我离开了这篇文章,因为上面的评论中有人问过它: 可以通过以下方式访问Docker Pipeline插件的文档:
答案 3 :(得分:0)
传递容器参数的另一种方法是使用inside方法。以下是摘自https://jenkins.io/doc/book/pipeline/docker/#caching-data-for-containers的示例(单击“切换脚本管道”链接以查看它)
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'
}
}
}