You can log into the Docker container using the root user (ID = 0) instead of the provided default user when you use the -u
option. E.g.
docker exec -u 0 -it mycontainer bash
root (id = 0) is the default user within a container. The image
developer can create additional users. Those users are accessible by
name. When passing a numeric ID, the user does not have to exist in
the container.
from Docker documentation
Update: Of course you can also use the Docker management command for containers to run this:
docker container exec -u 0 -it mycontainer bash