micooz / docker-lnmp

:unamused: Deploy lnmp(Linux, Nginx, MySQL, PHP7) using docker.
MIT License
304 stars 151 forks source link

Why use sudo? #4

Open 1e0ng opened 8 years ago

1e0ng commented 8 years ago

Hi, I noticed the following command is prefixed with sudo. It seems not good to use root privilege. Actually in the docker container, you can get root access, so no need to give it host's root privilege. Agree?

sudo docker-compose up
micooz commented 8 years ago

The docker daemon needs to do a lot of things which really require root rights.

Running containers (and applications) with Docker implies running the Docker daemon. This daemon currently requires root privileges, and you should therefore be aware of some important details.

see: https://docs.docker.com/engine/security/security/

1e0ng commented 8 years ago

If you just use docker-compose up, do you get errors? In my environment, it just works. Yes, the docker daemon currently requires root privilege, but the docker-compose is kind of some clients of the docker daemon, it doesn't need root privilege.

micooz commented 8 years ago

Ubuntu 14.04.4 LTS

Run docker-compose up without sudo gets:

ERROR: Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running?

docker-compose is a set of python scripts, create containers will call docker run actually.

What is your operating system?

1e0ng commented 8 years ago

I'm using OS X. I don't think this is an issue OS dependently. Maybe your error is caused by this.

I know the docker-compose calls docker run, and I think both of them don't need root privilege. You can see the official guide, and in there they just use

$ docker-compose up
micooz commented 8 years ago

The examples in the README assume that your are in production, usually Linux, not OS X.

Are there any evidence to prove that the user is not root in the official guide?

I know docker containers can be created without sudo in OS X, but it depends on a VM. Maybe you should check out the user privileges of docker deamon in your VirtualBox.

1e0ng commented 8 years ago

Yes, the $ sign is an evidence. Note the official guid use the $ sign, which means it's not a root user. If it's a # sign, it means a root user.