Search code examples
dockeramazon-ecr

Why is docker pushing old code to remote server


I've tried pushing the newly built image to ECR but it seemed that it always kept pushing the old code from cache to ECR. I've tried to clear out cache with the following commands and rebuilt the image but the issue remained:

  • Clear out docker
docker rmi $$(docker images | grep none | awk '{print $$3}') -f
docker system prune -a -f
  • Rebuild the image
docker build -t $(DOMAIN)/$(REPO_NAME):$(IMAGE_VERSION) -f docker/Dockerfile . --no-cache
  • pushing the image to ECR
docker push $REPO_ID.dkr.ecr.$REGION.amazonaws.com/$(DOMAIN)/$(REPO_NAME):$(IMAGE_VERSION)

I've tested the built image locally and it works with the new code. However, when I run the image remotely, it ran the old code and failed

I have no idea what was going on. Can someone help me on this please?


Solution

  • I have sorted this out. I would need to update the function image by the following:

    aws lambda update-function-code --function-name my-lambda-func --image-uri $REPO_ID.dkr.ecr.$REGION.amazonaws.com/$(DOMAIN)/$(REPO_NAME):latest