我正在运行docker-compose
容器的Kubernetes容器中运行Jenkins构建。进入docker-compose
容器后,我运行了名为docker-compose
的{{1}}服务,但是它无法建立图像,因为它无法连接到互联网。
我尝试将app_test
设置为network_mode
,这解决了问题,但是我需要为每个构建生成一个postgresql实例,因此我必须使用docker的网络。我还尝试将host
文件中的dns
和network_mode
分别分别设置为docker-compose.test.yml
和8.8.8.8
,这是行不通的。
bridge
docker-compose.test.yml
Jenkinsfile
version: "3.4"
services:
postgresql:
image: postgres:9.5.14
app_test:
build:
context: .
dockerfile: Dockerfile.test
dns: 8.8.8.8
network_mode: "bridge"
我希望容器能够安装来自def label = "worker-${UUID.randomUUID().toString()}"
env.ENVIRONMENT = "TEST"
podTemplate(label: label, containers: [
containerTemplate(name: 'docker', image: 'docker', command: 'cat', ttyEnabled: true),
containerTemplate(name: 'docker-compose', image: 'tmaier/docker-compose', command: 'cat', ttyEnabled: true)
],
volumes: [
hostPathVolume(hostPath: '/var/run/docker.sock', mountPath: '/var/run/docker.sock'),
...some secret volumes
]) {
node(label) {
def myRepo = checkout scm
def gitCommit = myRepo.GIT_COMMIT
stage('Run backend tests') {
container('docker-compose') {
sh "docker-compose -p ${gitCommit} -f docker-compose.test.yml up -d postgresql"
// `docker-compose run` automatically tries to build the service's image and
// fails because it can't connect to the internet
sh "docker-compose -p ${gitCommit} -f docker-compose.test.yml run app_test python -m pytest tests/"
}
}
}
}
的依赖项,但是出现了这个错误:
Dockerfile