使用docker而无须加sudo

来源:互联网 发布:海康威视网络摄像头 编辑:程序博客网 时间:2024/05/16 18:39

The docker daemon always runs as the root user, and since Docker version 0.5.2, 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 so, by default, you can access it with sudo.
Starting in version 0.5.3, if you (or your Docker installer) create a Unix group called docker and add users to it, then the docker daemon will make the ownership of the Unix socket read/writable by the docker group when the daemon starts. The docker daemon must always run as the root user, but if you run the docker client as a user in the docker group then you don’t need to add sudo to all the client commands.
原文

从0.5.2开始docker的守护进程总是以root用户来运行。docker守护进程绑定的是Unix的socket而不是一个TCP端口。Unix的socket默认属于root用户,所以,使用docker时必须加上sudo。

从0.5.3开始,创建一个名为docker组,然后将用户加入这个组内。当docker守护进程启动时,它会把Unix的读写权限赋予docker组。这样,当你作为docker组内用户使用docker客户端时,你就无须使用sudo了。

   # Add the docker group if it doesn't already exist.    sudo groupadd docker    # Add the connected user "${USER}" to the docker group.    # Change the user name to match your preferred user.    # You may have to logout and log back in again for    # this to take effect.    sudo gpasswd -a ${USER} docker    # Restart the docker daemon.    sudo service docker restart
0 0
原创粉丝点击