0

I am running moto server using the command

moto_server ecr -p 5000 -H 0.0.0.0

I created an ECR repo using the moto server with the command,

aws ecr create-repository --repository-name test --endpoint-url http://localhost:5000 --region us-east-1

Now can anybody please help on how to push a docker image to this ecr repo created using moto server?

Malathi
  • 2,119
  • 15
  • 40
  • Is this moto server a mock of aws ecr? – JRichardsz Apr 10 '21 at 17:16
  • yes moto server is a mock for many aws services. https://github.com/spulec/moto – Malathi Apr 10 '21 at 17:36
  • ECR is a docker registry which is a server running in some port. If moto is able to mock it, some endpoints should be available to test. Use this to test your mocked ecr server: `curl -X GET https://myregistry:5000/v2/_catalog`. I think in your case is localhost. Also try to get the used port with `netstat -tulpn` para linux or `netstat -aon` for windows. If this works. The image upload is a piece of cake :b – JRichardsz Apr 10 '21 at 17:45
  • TIL moto exists :) . If this was classic ECR before being able to push an image you would first need to authenticate ([see here](https://docs.amazonaws.cn/en_us/AmazonECR/latest/userguide/registry_auth.html)) and then you'd need to push an image using something along the lines of `docker push aws_ACCOUNT_ID.dkr.ecr.REGION.amazonaws.com/YOURIMAGE:TAG`. Eager to learn know exactly how moto mock all this (if it does). – mreferre Apr 10 '21 at 19:08
  • @JRichardsz There is no private registry in case of the ECR by moto. Please check my answer for the workaround. – Malathi Apr 11 '21 at 09:08
  • @mreferre Moto is just a mock for AWS. Hence the docker calls to pull or push an image is not possible. https://github.com/spulec/moto/issues/3852 – Malathi Apr 11 '21 at 09:09

1 Answers1

1

After going through the code I found that the put-image command actually adds an image to the repository. In the case of ECR by AWS this command is used by AWS to add metadata of the image uploaded via the docker push command.

# aws ecr put-image --repository-name test --region us-east-1 --image-manifest test --endpoint-url http://localhost:5000 --image-tag v1
{
    "image": {
        "registryId": "012345678910",
        "repositoryName": "test",
        "imageId": {
            "imageDigest": "sha256:a6698ae96409579a4f8ac96f5e5f276467b3f62d184c9e6db537daeedb9dd939",
            "imageTag": "v1"
        },
        "imageManifest": "test"
    }
}

# aws ecr list-images --repository-name test --region us-east-1 --endpoint-url http://localhost:5000
{
    "imageIds": [
        {
            "imageDigest": "i don't know",
            "imageTag": "v1"
        }
    ]
}

Luckily my code doesn't need to push or pull image from the ECR repo. This method might not work if that is the case.

Malathi
  • 2,119
  • 15
  • 40