简体   繁体   English

Docker 中的 Jenkins - 如何安装 docker-compose

[英]Jenkins in Docker - how to install docker-compose

So I want to start using Jenkins to build my app and then test it and push my image to local repo.所以我想开始使用 Jenkins 来构建我的应用程序,然后对其进行测试并将我的图像推送到本地仓库。 Because I have 2 images to push I would like to use docker-compose, but docker-compose is missing.因为我有 2 个要推送的图像,所以我想使用 docker-compose,但是缺少 docker-compose。

I installed Jenkins through Portainer, and I'm using the jenkins/jenkins:lts image.我通过 Portainer 安装了 Jenkins,我使用的是 jenkins/jenkins:lts 映像。

Is there a way to install docker-compose into the container without having to create my own Dockerfile for it?有没有办法将 docker-compose 安装到容器中,而无需为此创建我自己的 Dockerfile?

My Jenkins pipeline so far is:到目前为止,我的 Jenkins 管道是:

node {
    stage('Clone repository') {
        checkout([$class: 'GitSCM',
            branches: [[name: '*/master' ]],
            extensions: scm.extensions,
            userRemoteConfigs: [[
                url: 'repo-link',
                credentialsId: 'credentials'
            ]]
        ])
    }

    stage('Build image') {
         sh 'cd src/ && docker-compose build'
    }

    stage('Push image') {
         sh 'docker-compose push'
    }
}

You can either install docker-compose during image build time (via Dockerfile):您可以在映像构建期间安装 docker-compose(通过 Dockerfile):

FROM jenkins/jenkins  
USER root  
RUN curl -L \  
  "https://github.com/docker/compose/releases/download/1.25.3/docker-compose-$(uname -s)-$(uname -m)" \  
  -o /usr/local/bin/docker-compose \  
  && chmod +x /usr/local/bin/docker-compose  
USER jenkins  

Or you can install docker-compose after the Jenkins container is already running via the same CURL command:或者您可以在 Jenkins 容器已经通过相同的 CURL 命令运行之后安装 docker-compose:

$ sudo curl -L https://github.com/docker/compose/releases/download/1.25.3/run.sh -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM