Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

run container as root user

Is there any way I can run container in k8s as root user or other user. Like in docker

docker run --user <user> <image>

Is there any yaml configuration for running with

like image 475
Itay Gil Avatar asked Jan 23 '18 16:01

Itay Gil


People also ask

How do I run a container as a root user?

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.

Is it OK to run container as root?

Running containers as root is a bad idea for security. This has been shown time and time again. Hackers find new ways of escaping out of the container, and that grants unfettered access to the host or Kubernetes node.

Should Docker run as root or user?

One of the best practices while running Docker Container is to run processes with a non-root user. This is because if a user manages to break out of the application running as root in the container, he may gain root user access on host.

Does Docker run as root?

The Docker daemon always runs as the root user. If you don't want to preface the docker command with sudo , create a Unix group called docker and add users to it. When the Docker daemon starts, it creates a Unix socket accessible by members of the docker group.


1 Answers

As described in the kubernetes docs, you can set the security context for the container and set the runAsUser property as such:

 containers:
  - name: ...
    image: ...
    securityContext:
      runAsUser: 0

This will make the container execute internally as the root user.

like image 101
yamenk Avatar answered Oct 10 '22 13:10

yamenk