I building a docker image from a Dockerfile (downloaded from git hub). In the Dockerfile, there is such a line:

RUN useradd -m user
USER user

after this all the subsequent procedures happened under "user". When I was using the image, however, I realized that I was stuck inside "user" and couldn't switch to root anymore, because I don't know the password for root. The password was never specified inside the Dockerfile. The image is based on Centos7

How did this happen and is there a way to get the password?

I would really appreciate any hints!

Thank you so much


Once you're running an unprivileged docker container, you can't switch up to root from here without having set up a root password.

Fortunately, you don't have to setup a root password (and you should not). Instead, you can spawn a new process or container as root with the -u option:

docker run -u root imagename


docker exec -u root containername bash

Hint: also add -it flag if you need to interact with the process on the terminal.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.