Why docker command need sudo 为什么运行docker命令需要sudo?

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值