JRDigital
JRDigital

Reputation: 1

Is there a way to switch from a rootless user to a root user in a Docker container

I created a RHEL 7 Docker container using the Dockerfile USER instruction to create a rootless user. I can exec into the container, issue the whoami command and I can identify myself as that non-root user. However, I cannot execute any root-equivalent command i.e. yum update because it prompts me for the root password. When I sudo or su - it prompts me for the root password even though I never assigned a password to root.

  1. Why is the system prompting me for a root password if I never created one? So I can elevate my rights and execute priviledge commands?

  2. Can you switch from a rootless user to root in a container that was created with a rootless user?

Upvotes: 0

Views: 1197

Answers (1)

larsks
larsks

Reputation: 311606

Why is the system prompting me for a root password if I never created one? So I can elevate my rights and execute privileged commands?

Because by default the root account is locked (so it looks like it has a password, but it's not a valid one).

Can you switch from a rootless user to root in a container that was created with a rootless user?

If you've installed and configure sudo you could become root in the container using sudo. However, rather than "switching" to the root account, it's probably easier to create a root shell using the -u argument to docker exec:

docker exec -u root -it mycontainer -- bash

Upvotes: 2

Related Questions