How Do You Run a Docker Container as a Non-root User?

Problem scenario
You run this command: docker run -it ubuntu bash

"docker: Got permission denied while trying to connect to the Docker daemon sockes/create: dial unix /var/run/docker.sock: connect: permission denied."

You do not want to run a Docker container as a privileged user (as a recommended practice).  What should you do?


Install Docker.  If you need assistance, see this posting.

1.  Run these commands:
sudo newgrp docker
sudo usermod -aG docker jdoe
  # Replace jdoe with the user you want to run the Docker container with.  You can use "whoami" to find out what user you are.

2.  If you were logged in as jdoe (the user you just added), log out and log back in.

3.  Now try again (e.g., run "docker run -it ubuntu bash").

Leave a comment

Your email address will not be published. Required fields are marked *