Sunday, June 14, 2020

Root password of a Docker container

Root User Privileges in a Docker Container


Often we will come across situations where the default user setting in docker container will be not be sufficient to perform operations. 

Lets say to kill a process, inspect or edit some system files, import certificates or even to install some tool..


We have few options to accomplish this..


Easiest of all:

docker exec -u 0 -it <container-name> bash
 
By default, "0" denotes root user. You can also choose to specify, simply as "root". Also its better to specify the working directory as below..

docker exec -u root -it --workdir / <container-name> bash



Other options that are available are during the container image build:

Make necessary file permissions, etc., during the image build in the Docker file

If all the packages are available in your Linux image, chpasswdin the dockerfile before the USER utility

Hope this helps..!!

No comments:

Post a Comment

feedback?

Root password of a Docker container

Root User Privileges in a Docker Container Often we will come across situations where the default user setting in docker container will be n...