Reference: https://stackoverflow.com/questions/51218233/docker-why-do-i-need-to-sudo-in-ubuntu

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?

Answer

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.

I overlooked that aspect of the setup, here are proper instructions: https://docs.docker.com/engine/install/linux-postinstall/

To create the docker group and add your user:

  1. Create the docker group.

    $ sudo groupadd docker
    
  2. Add your user to the docker group.

    $ sudo usermod -aG docker $USER
    
  3. Log out and log back in so that your group membership is re-evaluated.

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐