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.
As an alternative, we can also access the Docker container as root. In this case, we'll use the nsenter command to access the Docker container. To use the nsenter command, we must know the PID of the running container. This allows us to access the Docker container as a root user and run any command to access any file.
Running a container as root means that the software packaged in a container is set to start as the root, or system administrator, user. This user is special in Linux systems, because it has all permissions needed to administer a system.
Running the container as root brings a lot of risks. Although being root inside the container is not the same as root on the host machine (some more details here) and you're able to deny a lot of capabilities during container startup, it is still the recommended approach to avoid being root .
Root inside the container is unprivileged and has restricted capabilities. This prevents the container from using system administration commands unless you manually add capabilities or use privileged mode when you start your containers. Despite this mitigation, allowing applications to run as root remains a hazard.
docker exec -u root -it <container-id> /bin/bash
Output (as seen in Terminal):
root@<container-id>:/#
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 -
You can connect as root in docker container using:
docker exec -u 0 -it <container_id> /bin/bash
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With