Once we create an image of an application & push it to Docker Container, then that tagged as latest one.
Now next time we need to rebuild & push the image the latest tag gets overridden.
But if the latest images gives any error then we should be able to get the previous tag to deploy.
Hence we need to create a separate tag for the current latest image before pushing the new image.
Below are the commands to do the same:
sudo docker tag <docker repo>/testwebapp:latest <docker repo>/testwebapp:prev
sudo docker push <docker repo>/testwebapp:prev
This will create a tag name prev (You can choose any name) of the present latest image.
This command should run before pushing the new image to Docker.