首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >詹金斯。并行运行docker容器(声明式)

詹金斯。并行运行docker容器(声明式)
EN

Stack Overflow用户
提问于 2019-10-04 04:47:06
回答 1查看 803关注 0票数 0

我想在声明性Jenkins管道中运行两个docker容器,因为我有一个后端容器,它使用Selenium服务器容器进行测试。我知道有一个脚本化的例子,但我想知道是否有声明选项。

脚本如下所示:

代码语言:javascript
复制
node {
checkout scm
docker.image('mysql:5').withRun('-e "MYSQL_ROOT_PASSWORD=my-secret-pw"') { c ->
    docker.image('mysql:5').inside("--link ${c.id}:db") {
        /* Wait until mysql service is up */
        sh 'while ! mysqladmin ping -hdb --silent; do sleep 1; done'
    }
    docker.image('centos:7').inside("--link ${c.id}:db") {
        /*
         * Run some tests which require MySQL, and assume that it is
         * available on the host name `db`
         */
        sh 'make check'
    }
}

}

EN

回答 1

Stack Overflow用户

发布于 2019-10-06 02:17:13

最后,我使用了here中的描述。withRun -在容器内的主机inside上执行命令

代码语言:javascript
复制
stage ('Test') {
            steps {
                // Create network where I will connect all containers
                sh 'docker network create test'
                script {
                    //withRun command starts the container and doesn't stop it untill all inside is executed.
                    //Commands inside are executed on HOST machine
                    docker.image('selenium/standalone-chrome').withRun("-p 4444:4444 --name=selenium -itd --network=test") {
                        docker.image("$CONTAINER_NAME:front").withRun("-p 3001:80 --name=front -itd --network=test") {
                            //We start backend container...
                            docker.image("$CONTAINER_NAME:back").withRun("-p 8001:80 --name=back -itd --network=test") {
                                //...and with inside command execute commands *surprise* inside the container
                                docker.image("$CONTAINER_NAME:back").inside("-itd --network=test") {
                                    //execute commands inside the container
                                }
                            }
                        }
                    }
                }
            }
        }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58226666

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档