Permission denied when running Docker after installing it as a Snap
This is from the GitHub page, did you try these exact steps:
If you are using Ubuntu Core 16,
Connect the docker:home plug as it's not auto-connected by default:
$ sudo snap connect docker:home
If you are using an alternative snap-compatible Linux distribution ("classic" in snap lingo), and would like to run docker as a normal user:
Create and join the docker group.
$ sudo addgroup --system docker
$ sudo adduser $USER docker
$ newgrp docker
You will also need to disable and re-enable the docker snap if you added the group while it was running.
$ sudo snap disable docker
$ sudo snap enable docker
From Docker snap github
The error message tells you that your current user can’t access the docker engine, because you’re lacking permissions to access the unix socket to communicate with the engine.
Temporary solution
Use the sudo
command to execute the commands with elevated permissions every time.
Permanent (suggested) solution
Add the current user to the docker
group. This can be achieved by typing
sudo usermod -a -G docker $USER
You have to log out and log in again for the group membership to take effect.
Source: techoverflow.net
I assume, your username is already in docker group. To check this, issue below command.
id -nG
If not you need to add your user into the docker group by below command.
sudo groupadd docker
sudo usermod -aG docker $USER
When you execute the command, sudo systemctl start docker
, it creates a docker process. That docker process contains dockerd
daemon thread. The command also creates default docker.sock
Unix socket. The docker.sock
socket is continuously listened by dockerd
daemon thread. This makes you can do kernel-level IPC with docker.pid
process. To be able to use this docker socket, you need to have proper permission from the process level (docker.pid
) and file level (docker.sock
). So, executing below two commands should solve your issue.
sudo chmod a+rwx /var/run/docker.sock # You can provide just execute permission
sudo chmod a+rwx /var/run/docker.pid
sudo setfacl -m user:your_user_name:rw /var/run/docker.sock
doesn't require a restart and is more secure
You should add the user to the Docker group (see the official docs).
You can add sudo
in front of the command or you can add the user in the docker
group by using this command:
sudo usermod -aG docker <USER>
Log out and log back in so that your group membership is re-evaluated.