首页 > 解决方案 > 从 Jenkinsfile 在 docker run 中设置网络

问题描述

docker run我的 Jenkinsfile 步骤中,我有以下内容:

docker.image('deployscript:latest').withRun("-e 'IMAGE=name:${BUILD_ID}' -e 'CNAME=name' -e 'CONFIG={\"HostConfig\":{\"NetworkMode\":\"host\"}}'") { c ->
    sh "docker logs ${c.id}"
}

部署后,已连接网络设置为bridge,但我需要将其设置为host

我已经尝试将这些添加到withRun参数中,但似乎都不起作用:

如何在 JenkinsfilewithRun参数中设置要托管的网络?

使用第一个选项 ( --network host),以下是实际运行的内容:

docker run -d -e 'IMAGE=name:94' -e 'CNAME=name' -e 'CONFIG={"HostConfig":{"NetworkMode":"host"}}' --network host deployscript:latest

为什么网络还是bridge用上面的命令设置的?

我希望其中一个可以工作:

docker.image('deployscript:latest').withRun("--network host")
docker.image('deployscript:latest').withRun("--network='host'")
docker.image('deployscript:latest').withRun("--network=host")
docker.image('deployscript:latest').withRun("--net=host")

标签: dockerjenkins

解决方案


推荐阅读