直接使用docker而無須加sudo

The sudo command and the docker Group

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時必須加上sudodocker

0.5.3開始,建立一個名爲docker組,而後將用戶加入這個組內。當docker守護進程啓動時,它會把Unix的讀寫權限賦予docker組。這樣,當你做爲docker組內用戶使用docker客戶端時,你就無須使用sudo了。socket

# 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

英文原文this

相關文章
相關標籤/搜索