Docker Permission Denied on Ubuntu 16.04

docker, ubuntu

Recently, I have been messing around with writing and deploying AWS Lambda Functions and Microsoft Azure Functions - two “serverless” technologies that have a lot of promise for certain applications.

For development environments, both rely on using docker images provided by the respective vendors to run your functions locally.

I attempted to set up Docker on Ubuntu 16.04 by running sudo apt install docker, which appeared to succeed.

However, when attempting to run docker run hello-world - a command which should pull a ‘hello world’ image from one of the public docker repositories, then run it - I received an error to the effect of:

1
docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock

The solution to this problem is to either (a) run your docker commands as root, or (b) add your login user to the docker group.

Option (a) is not preferred, as introducing a sudo dependency will quickly lead you to ‘sudo hell’ where everything of use requires sudo.

For option (b), you can run sudo usermod -a -G docker $USER, which will add your user to the docker group.

For the change to take effect, you will need to fully log out of your account and log back in.


I'm looking for better ways to build software businesses. Find out if I find something.