简体   繁体   中英

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 . I am trying to do the next step which is running the image via Jenkins to ECS.

following is my jenkins file:

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. Any help would be appreciated.

In the case of ECS, docker run is not enough. You need the following to run container on AWS ECS.

  • AWS ECS cluster
  • ECR image
  • Task definition
  • IAM role for service
  • 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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