我有一个 Jenkinsfile,我试图在其中执行npm run test一个容器。当我用inside它运行时会失败,但是当我用withRun它运行时会按照我的意愿运行。
代码参考 inside
stage('Test') {
docker.image('justinribeiro/chrome-headless').inside ("-p 9222:9222 --security-opt seccomp=$WORKSPACE/chrome.json") {
sh label:
'Running npm test',
script: '''
npm run test
'''
}
}
Run Code Online (Sandbox Code Playgroud)
和 withRun
stage('Test') {
docker.image('justinribeiro/chrome-headless').withRun ("-p 9222:9222 --security-opt seccomp=$WORKSPACE/chrome.json") {
sh label:
'Running npm test',
script: '''
npm run test
'''
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想了解它们之间的区别是什么。
我观察到inside增加了卷并cat在容器上运行,而withRun没有。
我还阅读了文档https://jenkins.io/doc/book/pipeline/docker/但理解得不够好。
更详细的解释将不胜感激。
谢谢。