Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker: why do I need to sudo in Ubuntu?

I am working through this tutorial setting up Docker, and I'm finding that all of their examples are written like

docker run hello-world

but when I try it, it says permission denied on a socket and I have to do

sudo docker run hello-world

to run the examples. Why are root privileges necessary even for these simple examples?

like image 269
adamconkey Avatar asked Jul 06 '18 22:07

adamconkey


People also ask

Why do I have to use sudo with Docker?

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 .

Do you need sudo to install Docker?

The installation script requires root or sudo privileges to install and use Docker. If you want to grant non-root users access to Docker, refer to the post-installation steps for Linux. Docker can also be installed without root privileges, or configured to run in rootless mode.

What is sudo Docker command?

A sys admin can use the sudo command to grant users access to Docker containers. To prevent security risks, understand the implications of sudo, root access and Docker groups. The root user accesses the Docker daemon and sockets on the host, with the ability to read and write images.

Should Docker run as root?

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 .


1 Answers

Running a docker container requires the user to be a member of the docker group. By default, when you install docker, the only user that is added to it is root. You can add your own user to this group if you want to run docker containers from it.

like image 68
Mureinik Avatar answered Sep 20 '22 23:09

Mureinik