Home > Blockchain >  I want to push already created docker images to aws ecr
I want to push already created docker images to aws ecr

Time:09-21

I have already created docker images, I want to push all the external docker images to aws ECR using script or CI/CD pipeline.

In one shot,I know AWS CodeBuild process. But is there any other way to do it?

CodePudding user response:

docker push

I have already created docker images

As you said, images created locally. So, you have these images in your filesystem.

For that case, you may want docker push.

E.g.

docker image push registry-host:<port>/myimagetag:latest

For ECS it would be

docker push aws_account_id.dkr.ecr.region.amazonaws.com/myimagetag:tag

migrator

There is a project docker-archive/migrator: Tool to migrate Docker images from Docker Hub or v1 registry to a v2 registry. Unfortunately the repository has been archived. But should work.

docker run -it \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -e AWS_ACCESS_KEY_ID=<key> \
    -e AWS_SECRET_ACCESS_KEY=<secret> \
    -e V1_REGISTRY=v1.registry.fqdn \
    -e V2_REGISTRY=v2.registry.fqdn \
docker/migrator

CodePudding user response:

There is a lot of ways for CI/CD. For example, you can use GitHub Actions

In the free account you have:

2,500 free credits/week
Run 1 job at a time
Build on Linux, Windows, and Arm

So, you can create a private repository and push all files with Dockerfile.

After that create Actions and configure a job that will build your Docker image and then push it to the ECR

There is Amazon ECR "Login" Action for GitHub Actions

    - name: Login to Amazon ECR
      id: login-ecr
      uses: aws-actions/amazon-ecr-login@v1

    - name: Build, tag, and push image to Amazon ECR
      env:
        ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
        ECR_REPOSITORY: my-ecr-repo
        IMAGE_TAG: ${{ github.sha }}
      run: |
        docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
        docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG

And it can work as:

  • You push changes to the repository
  • Actions start, build a docker image and then push docker image to the AWS ECR.
  • Related