Docker: Run Docker without sudo


In this post I will show you about how to use Docker without using sudo command.

by the way, these are errors you may have if you run Docker commands without enough permission access:

Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.26/containers/json: dial unix /var/run/docker.sock: connect: permission denied

or an error like this:

docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.26/containers/create: dial unix /var/run/docker.sock: connect: permission denied.
See ‘docker run –help’.

Snapshot of docker permission Errors :

Error1Error2

To fix this kind of issue is fairly easy, you just need to add your user to docker group so your current user account will have access to the docker command, here is step by step instruction to add your user to docker group:

  1. Make sure that your docker service is running

    sudo /etc/init.d/docker status

  2. Create new docker group (in case  the previous one is not exist)

    sudo groupadd docker

    groupadd: group ‘docker’ already exists

  3. add your current logged in user t the docker group

     sudo usermod -aG docker $USER

  4. Restart docker daemon / service

    sudo service docker restart

  5. re-login your current user

    su ${USER}

    error3.png

  6. That’s all, have fun…
Advertisements

One thought on “Docker: Run Docker without sudo

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s