【发布时间】:2019-09-16 19:19:03
【问题描述】:
我正在使用kubernetes-plugin,但在 K8S pod 上构建 docker 镜像时遇到了一些问题:
我正在创建 POD:
podTemplate(containers: [
containerTemplate(
name: 'docker-build',
image: 'docker',
command: 'cat',
ttyEnabled: true
)
],
volumes: [
hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock')
])
{
node(POD_LABEL) {
stage("Checkout") {
dir("${env.WORKSPACE}/code") {
script {
// Checkout - Works
}
}
}
stage ('Build docker images') {
container('docker-build') {
dir("${env.WORKSPACE}/code") {
sh """
./build-images
"""
}
}
}
}
}
但它在 docker build 步骤失败:
Err:1 http://deb.debian.org/debian stretch InRelease
Temporary failure resolving 'deb.debian.org'
Err:2 http://security.debian.org/debian-security stretch/updates InRelease
Temporary failure resolving 'security.debian.org'
Err:3 http://deb.debian.org/debian stretch-updates InRelease
Temporary failure resolving 'deb.debian.org'
Reading package lists...
[91mW: Failed to fetch http://deb.debian.org/debian/dists/stretch/InRelease Temporary failure resolving 'deb.debian.org'
W: Failed to fetch http://security.debian.org/debian-security/dists/stretch/updates/InRelease Temporary failure resolving 'security.debian.org'
W: Failed to fetch http://deb.debian.org/debian/dists/stretch-updates/InRelease Temporary failure resolving 'deb.debian.org'
W: Some index files failed to download. They have been ignored, or old ones used instead.
[0mReading package lists...
Building dependency tree...
Reading state information...
[91mE: Unable to locate package libpam-dev
E: Unable to locate package libpcap0.8-dev
E: Couldn't find any package by glob 'libpcap0.8-dev'
E: Couldn't find any package by regex 'libpcap0.8-dev'
E: Unable to locate package libpq5[0m[91m
E: Unable to locate package libtins-dev
E: Unable to locate package openjdk-8-jdk-headless
E: Unable to locate package python3
当使用kubectl exec 访问 POD 并尝试构建时,它会因相同的错误而失败:
docker build -t my_test .
当尝试使用--network=host 构建相同的它可以工作:
docker build --network=host -t my_test .
我试图理解为什么它需要--network=host 才能工作。
顺便说一句 - 当我在 Jenkins slave pod 中并尝试下载任何包或访问互联网时,一切正常,只有当我尝试构建 docker 映像并尝试下载时才会发生在这个过程中打包。
我怀疑docker build 失败是因为某些网络配置错误,或者可能是 docker 网络在此 docker build on docker 期间处于不良状态..
到目前为止我已经尝试过:
- 使用
hostNetwork: true创建 pod,但没有帮助。 - 使用
privileged: true创建 pod,但没有帮助。 - 许多其他 hack 使 pod 在不同的网络上运行,但也没有帮助。
请帮忙。
【问题讨论】:
标签: docker jenkins kubernetes