docker - 从 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
参数中,但似乎都不起作用:
--network host
--network='host'
--network=host
--net=host
如何在 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")
解决方案
推荐阅读
- java - java.lang.IllegalStateException:不是标准目录之一
- java - 将“2020-10-31T00:00:00Z”字符串日期转换为长
- perforce - Perforce P4Api.net add file get this Can't add filenames with wildcards [@#%*] in them
- java - 如果本地方法的包或类或方法名称被混淆,yGuard 现在会发出警告
- node.js - Firebase 堆栈“错误:实体的索引条目过多”
- android - 将凌空响应添加到全局变量
- excel - 如何在 excel 嵌套 AND 公式中显示哪些 AND 条件失败
- python - Neo4j 导入 csv 并在一列中拆分值
- python - 为什么代码的结果是-5,而不是-4?
- c++ - 如何避免分段错误