88

I just installed docker and created a group and added my username to it to avoid using sudo every time. However when I do the test and run docker run hello-world it gives me following error: WARNING: Error loading config file:/home/user/.docker/config.json - stat /home/user/.docker/config.json: permission denied

But then it continues and gives a success message:Hello from Docker. This message shows that your installation appears to be working correctly. Any ideas whats wrong and what implications does it have?

Trm
  • 1,015
  • 1
  • 9
  • 6
  • The official documentation has a nice section named [Manage Docker as a non-root user](https://docs.docker.com/install/linux/linux-postinstall/). – aspretto Mar 12 '19 at 16:45

1 Answers1

180

Try running

sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
sudo chmod g+rwx "/home/$USER/.docker" -R

$USER is the username of the currently logged in user.

Grammargeek
  • 2,762
  • 2
  • 14
  • 24
  • thanks, that seem to have done it. Just a question, since I changed ownership to my user. Would it be better to change ownership to a group: docker? – Trm Mar 19 '16 at 13:06
  • 1
    was a bit too fast and ran command from earlier root login. I still get the same error. I even tried running: `sudo chown user:docker /home/user/.docker/config.json`, but it didn't help – Trm Mar 19 '16 at 13:21
  • Hmm :/ What's the output of `ls -la /home/user/.docker/` @Trm ? – Grammargeek Mar 19 '16 at 19:56
  • 2
    Hi. I moved away the file and everything seems to work fine now. – Trm Mar 20 '16 at 00:44
  • 2
    Cool @Trm I wonder if you maybe needed to do `chown -R USER:DOCKER /home/USER/.docker` ? – Grammargeek Mar 20 '16 at 14:57
  • I haven't tried to chown dir itself but only the file directly (see 2nd comment). I'm quite new to Linux, but is there a difference `chown -R USER:DOCKER /home/USER/.docker` vs `chown user:docker /home/user/.docker/config.json` for this specific file? – Trm Mar 20 '16 at 15:26
  • `chown -R USER:DOCKER /home/USER/.docker` sets the permissions for the directory and all its files. `chown user:docker /home/user/.docker/config.json` will do just the file. – Grammargeek Mar 20 '16 at 15:48
  • What's the output of `ls -la /home/user/.docker`? – Grammargeek Mar 20 '16 at 15:49
  • `drwx------ 2 root root 4096 mar 18 19:59 . drwxr-xr-x 47 user user 4096 mar 20 15:22 .. -rw------- 1 user docker 131 mar 18 19:59 config.json` – Trm Mar 20 '16 at 15:55
  • I've got it! Try running `sudo chmod -R g+rw /home/user/.docker` – Grammargeek Mar 20 '16 at 15:57
  • Perfect works like a charm now. If I understand correctly, while I owned the file, I did not have rw permissions and now I added them? – Trm Mar 20 '16 at 16:00
  • No, @Trm you had write permissions. `-rw-------` means only you have permissions. Not the group. g+rw adds read/write permissions to anyone in the docker group – Grammargeek Mar 20 '16 at 16:12
  • ok. many thanks for your time! much appreciated. – Trm Mar 20 '16 at 16:26
  • If you set the .docker folder as `g+rw` docker group members can not read the files inside the folder, only list them. To read files in a folder you need also execute permission (`g+rwx` ) on that folder. – dfherr Dec 14 '16 at 12:39
  • 5
    For the lazy: `sudo chown $(whoami):docker /home/$(whoami)/.docker/config.json` just copy paste. – SWiggels Jun 08 '17 at 09:07