Docker doesn't recommend running an apt-get upgrade and dist-upgrade on a docker image as many of the "essential" packages from the partent image cannot upgrade inside an unprevileged container. take a look at the Docker best practices
That is not good design to have docker or any lib update after logging into the container. As mentioned by Andrea Giaime Bodei , you need to update the base image in the Dockerfile and rebuild the image. The docker images are immutable.
# Download base image ubuntu 20.04
# LABEL about the custom image