Why is docker pushing old code to remote server

Viewed 446

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?

3 Answers

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

You don't explicitly say where/how you are running that image "remotely". Could it be that you are re-using tags and those images are cached on the "remote" nodes you are deploying to (e.g. EKS cluster or ECS/EC2 cluster)? In that case, depending on the host configuration/state it may not even reach to ECR to pull the new image if the node (thinks to have) found the same image cached.

[Update] Following up from the comments, the problem occurs in a Lambda function and this blog has hints about how to update the code in the Lambda.

At first sight, the issue is that there is a mismatch in the name (a.k.a. tag) of the two images:

docker build -t $(DOMAIN)/$(REPO_NAME):$(IMAGE_VERSION) -f docker/Dockerfile . --no-cache

docker push $REPO_ID.dkr.ecr.$REGION.amazonaws.com/$(DOMAIN)/$(REPO_NAME):$(IMAGE_VERSION)

so you should probably write:

docker build -t $REPO_ID.dkr.ecr.$REGION.amazonaws.com/$(DOMAIN)/$(REPO_NAME):$(IMAGE_VERSION) -f docker/Dockerfile . --no-cache

instead.

Related