Login to Docker container with root privileges
In this little post , let’s see how to login to the shell of a docket container with root privileges.
To login to a running container, I usually use the following command.
docker exec -it <container-id> sh
Sometimes I need to run commands with root privileges inside a container. –user flag lets pass the username or UID. Its shorthand notation is -u
docker exec -it -u 0 <container-id> sh
Passing -u 0 to the docker exec command lets you login with root privileges.