Using testcontainers in a Jenkins Docker Agent: containers fail to start, NoRouteToHostException

后端 未结 2 539
小鲜肉
小鲜肉 2021-01-14 00:13

I\'m using a Jenkins declarative pipeline with Docker Agents to build and test my software, including running integration tests using testcontainers. I can run my testcontai

2条回答
  •  长情又很酷
    2021-01-14 00:56

    In my case it was enough to add two arguments to Docker agent options:

    • Docker socket as volume
    • add --group-add parameter with ID of docker group
    pipeline {
        agent any
        stages {
            stage('Gradle build') {
                agent {
                    docker {
                        reuseNode true
                        image 'openjdk:11.0-jdk-slim'
                        args  '-v /var/run/docker.sock:/var/run/docker.sock --group-add 992'
                    }
                }
    
                steps {
                    sh 'env | sort'
                    sh './gradlew build --no-daemon --stacktrace'
                }
            }
        } // stages
    } // pipeline
    

提交回复
热议问题