Kubernetes - Jenkins - Docker-compose Unable to connect to internet

10/15/2019

I'm running a Jenkins build inside a Kubernetes pod that's running a docker-compose container. Once inside the docker-compose container I run up a docker-compose service titled app_test, however it's unable to build the image because it can't connect to the internet.

I've tried setting network_mode to host, and that solves the problem, however I need to spawn up a postgresql instance for each build, so I have to use docker's networking. I also tried setting the dns and network_mode explicitly in the docker-compose.test.yml file to 8.8.8.8 and bridge, respectively, which didn't work.

docker-compose.test.yml

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"

Jenkinsfile

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/"
      }
    }
  }
}

I expected the container to be able to install the dependencies from the Dockerfile, however I got this error:

Building app_test

Step 1/7 : FROM python:3.7.3-slim

 ---> 338ae06dfca5

Step 2/7 : RUN apt-get update && apt-get install -y     libcurl4-openssl-dev     libssl-dev     gcc     xvfb     qpdf     wkhtmltopdf     build-essential     libffi-dev     python-dev

 ---> Running in 2450e20e1da6

Err:1 http://deb.debian.org/debian stretch InRelease

  Temporary failure resolving 'deb.debian.org'

Err:2 http://deb.debian.org/debian stretch-updates InRelease

  Temporary failure resolving 'deb.debian.org'

Err:3 http://security.debian.org/debian-security stretch/updates InRelease

  Temporary failure resolving 'security.debian.org'

Reading package lists...

W: 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.

Reading package lists...

Building dependency tree...

Reading state information...

E: Unable to locate package libcurl4-openssl-dev

E: Unable to locate package libssl-dev

E: Unable to locate package gcc

E: Unable to locate package xvfb

E: Unable to locate package qpdf

E: Unable to locate package wkhtmltopdf

E: Unable to locate package build-essential

E: Unable to locate package libffi-dev

E: Unable to locate package python-dev

Service 'app_test' failed to build: The command '/bin/sh -c apt-get update && apt-get install -y     libcurl4-openssl-dev     libssl-dev     gcc     xvfb     qpdf     wkhtmltopdf     build-essential     libffi-dev     python-dev' returned a non-zero code: 100

script returned exit code 1
-- Michael Laythe
docker
docker-compose
jenkins
kubernetes

0 Answers