Search code examples
dockerrootsudo

Switch to Docker Root User


I am working on Docker and before i execute any command on Docker CLI , I need to switch to root used using the command

sudo su - root

Can anyone please tell me why we need to switch to root user to perform any operation on Docker Engine?


Solution

  • you don't need to switch to root for docker cli commands and it is common to add your user to the docker group

    sudo groupadd docker
    sudo usermod -aG docker $USER
    

    see: https://docs.docker.com/engine/install/linux-postinstall/#manage-docker-as-a-non-root-user

    the reason why docker is run as root:

    The Docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user root and other users can only access it using sudo. The Docker daemon always runs as the root user.