A little convoluted… but I think this should work:
# First, make sure you've got the latest base image locally
docker pull discourse/mail-receiver:release
# Get the top layer of the base image
BASE_IMAGE_HASH=$(docker history discourse/mail-receiver:release -q | head -n 1)
# Get the layers of the **running** version
RUNNING_IMAGE_HASH=$(docker container inspect mail-receiver -f "{{.Image}}")
RUNNING_IMAGE_LAYERS=$(docker history $RUNNING_IMAGE_HASH -q)
# Check if the running image layers include the current base image:
[[ "$RUNNING_IMAGE_LAYERS" == *"$BASE_IMAGE_HASH"* ]] && echo "Up to date"
That will print “Up to date” if you’re up to date. Otherwise, the final line will print nothing, and exit with a non-zero status.