Alexey Starinsky
Alexey Starinsky

Reputation: 4275

Become root in a docker container

I installed Oracle Database in a Docker container, but can't figure out how to become root. If I to this from the host

sudo docker exec -it -u 0 oracle18se /bin/bash

or

sudo docker exec -it --user root oracle18se /bin/bash

I get

OCI runtime exec failed: exec failed: container_linux.go:345: starting container process caused "chdir to cwd (\"/home/oracle\") set in config.json failed: permission denied": unknown

If I do

sudo docker exec -it oracle18se /bin/bash

from the host, and then

su -

from the container, it asks the root password, but I do not know it.

Hy host OS is Ubuntu 18.04, link to docker file

EDIT1:

Found a Docker bug.

Upvotes: 25

Views: 38816

Answers (3)

DUDANF
DUDANF

Reputation: 2990

You can exec into an existing container

docker exec -u root -it <container-id> /bin/bash

Output (as seen in Terminal):

root@<container-id>:/#

And to set root password use this:

Type the following command to become root user and issue passwd:

sudo -i
passwd

OR set a password for root user in a single go:

sudo passwd root

Test it your root password by typing the following command:

su -

Upvotes: 36

Alexey Starinsky
Alexey Starinsky

Reputation: 4275

The workaround is

sudo docker exec -u 0 -it --workdir / oracle12se /bin/bash

Upvotes: 2

banuj
banuj

Reputation: 3230

You can connect as root in docker container using:

docker exec -u 0 -it <container_id> /bin/bash

Upvotes: 8

Related Questions