简体   繁体   English

如何通过 Jenkins CD 在 ECS 中的 ECR 中运行 docker 映像?

[英]How to run a docker Image in ECR in ECS via Jenkins CD?

I am trying to run a docker container in ECS , I have already managed to push the Image to ECR via Jenkins .我正在尝试在ECS中运行 docker 容器,我已经设法通过Jenkins将图像推送到ECR I am trying to do the next step which is running the image via Jenkins to ECS.我正在尝试执行下一步,即通过 Jenkins 将映像运行到 ECS。

following is my jenkins file:以下是我的 jenkins 文件:

node{
        stage('SCM Checkout'){
         git branch : 'my-branch', credentialsId: 'git-credentials-for-jenkins', url: 'git-url'
        }
        stage('Build Docker Image'){
         sh 'docker build -t my-app:latest ./my-app'
        }
        stage('Push Docker Image to ECR'){
         def file = readFile('./my-app/Version')
         def version = file.trim()
         docker.withRegistry("XXXXXXXX.amazonaws.com", "aws-credentials"){
          docker.image("my-app").push(version)
         }
        }

        stage("Deploy") {
            // what to do here ?

        }
        }

my jenkins instance is on AWS.我的 jenkins 实例在 AWS 上。 Any help would be appreciated.任何帮助,将不胜感激。

In the case of ECS, docker run is not enough.在 ECS 的情况下, docker run是不够的。 You need the following to run container on AWS ECS.您需要以下内容才能在 AWS ECS 上运行容器。

  • AWS ECS cluster AWS ECS 集群
  • ECR image ECR 图像
  • Task definition任务定义
  • IAM role for service服务的 IAM 角色
  • Service服务

So you can automate the last four-step and better to create the first one manually or also not bad to make this automatic but this one-time creation in the life cycle.因此,您可以自动化最后四个步骤,更好地手动创建第一个步骤,或者使此步骤自动化,但在生命周期中一次性创建。

You can check this AWS offical documentation to work with ECS in jenkins.您可以查看此AWS 官方文档以使用 jenkins 中的 ECS。

devops/set-up-a-build-pipeline-with-jenkins-and-amazon-ecs devops/set-up-a-build-pipeline-with-jenkins-and-amazon-ecs

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

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