在Jenkinsfile中运行映像时如何传递Docker容器参数 [英] How to pass docker container arguments when running the image in a Jenkinsfile

查看:569
本文介绍了在Jenkinsfile中运行映像时如何传递Docker容器参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个以结尾的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆