[英]How to pass arguments to a docker container at start when running an image of dot net core console
[英]How to pass docker container arguments when running the image in a Jenkinsfile
我有一個以
ENTRYPOINT ["node", "index.js"]
CMD ["--help"]
index.js
可以采用幾個不同的參數,我還需要為容器公開一個端口,因此如果我手動運行它,我會執行以下操作:
docker run -p 3000:3000 my_container:latest --arg1 somearg --arg2 anotherarg
我如何在 Jenkinsfile 中做到這一點? 我的測試將與此容器通信,因此它需要在我運行測試之前運行。 我使用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'
}
}
您可以使用 withRun 的第二個參數
.withRun('-p 3000:3000', '--arg1 somearg --arg2 anotherarg')
使用.withRun('-p 3000:3000', '--arg1 arg1 --arg2 arg2')
。 相關文檔位於此處的 docker-workflow-plugin 中。
傳遞容器參數的另一種方法是使用 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'
}
}
}
我離開這篇文章是因為它在上面的評論中被問到:Docker Pipeline 插件的文檔可以這樣訪問:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.