The above command will create the baeldung image. Let's run the command to build the image: $ docker build -t baeldung. After that, we'll use it as a default user. We're also using the chpasswd command to add a password to the john user. This Dockerfile uses the image “ ubuntu:16.04 ” as the base image, installs the sudo package, and creates a new user, “ john “. RUN useradd -m john & echo "john:john" | chpasswd & adduser john sudo RUN apt-get update & apt-get -y install sudo Let's check out the Dockerfile: FROM ubuntu:16.04 When this user needs extra privileges, it can access them using the s udo command. Importantly, we'll also install the sudo package in the Docker container while building the image. Here we'll create a Dockerfile, and add a new user. To share resources with different privileges, we may need to create additional users inside a Docker container. This allows us to access the Docker container as a root user, and run any command to access any file.ĭocker containers typically run with root as the default user. Once we have the PID, we'll use it with the nsenter command in the following way: $ nsenter -target 6491 -mount -uts -ipc -net -pid Let's take a look at the command to get the PID of the container: $ docker inspect -format baeldung To use the nsenter command, we must know the PID of the running container. In this case, we'll use the nsenter command to access the Docker container. With the root user's full privileges, we can change any file without a problem.Īs an alternative, we can also access the Docker container as root. We can see from the above output that the update command succeeded, and the root user has access to the lock file. Now we can perform any operations on the container: $ apt-get update This time, we entered the container as a root user. In order to check the current user details, we'll run the whoami command: $ whoami ![]() We can also use the user name in this command: $ docker exec -it -u root baeldung bash Using the “ -u” option of the docker exec command, we'll define the id of the root user.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |