By bitmap
I’ve just installed docker but I have to run it with sudo every time. If I don’t add sudo I get the following error:
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.40/containers/json: dial unix /var/run/docker.sock: connect: permission denied
Is there a way around that? I want to be able to run docker without having to type my password each time…
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Accepted Answer
Hello,
According to the official Docker docs here:
https://docs.docker.com/install/linux/linux-postinstall/#manage-docker-as-a-non-root-user
You need to do the following:
To create the docker group and add your user:
sudo groupadd docker
sudo usermod -aG docker ${USER}
su -s ${USER}
docker run hello-world
This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.
If you initially ran Docker CLI commands using sudo before adding your user to the docker group, you may see the following error, which indicates that your ~/.docker/
directory was created with incorrect permissions due to the sudo commands.
WARNING: Error loading config file: /home/user/.docker/config.json -
stat /home/user/.docker/config.json: permission denied
~/.docker/
directory (it is recreated automatically, but any custom settings are lost), or change its ownership and permissions using the following commands:sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
sudo chmod g+rwx "$HOME/.docker" -R
Here’s also a quick video demo on how to do this:
Also I came across this useful guide here as well: How to Fix Docker: Permission Denied
Hope that this helps!
Regards,
Bobby
The above is almost right, but opens up a security gap that let’s everyone get access to docker.sock
Instead of sudo chmod 666 /var/run/docker.sock
which opens it to everyone, enter
sudo chown root:docker /var/run/docker.sock
That way root still has it’s connection with docker but anyone in the docker group gets access too.
If you run into this:
ubuntu@ip-x-x-x-x:~$ docker login -u username -p password
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Error saving credentials: error storing credentials - err: exit status 1, out: `Cannot autolaunch D-Bus without X11 $DISPLAY`
Try this: sudo apt install gnupg2 pass
See this github answer for details: https://github.com/docker/cli/issues/1136#issuecomment-459649905
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.