Score:1

Ubuntu 20.04 + Docker: correct folder permissions

kp flag

When I was setting up Ubuntu 20.04, I opted for Docker to be installed as well. I haven't made any changes to its settings (i.e. I believe Docker runs as root), apart from creating a docker group and adding my user to it.

My containers store their data in /home/docker. In order for me to be able to FTP into the folder and add/edit some files, I changed the ownership of all subfolders to myuser:myuser. As a result, this morning SQL was not functioning properly. I finally figured I should restore ownership to root:root, which allowed me to view all databases and tables using phpMyAdmin.

However, when I try to connecto using DBeaver, I keep getting an error that looks like this:

Can't read dir of './database1/' (errno: 13 "Permission denied")

Could someone please tell me the best way to set the permissions of the docker folder and what other settings I should change in order for all containers to function properly and for me to be able to FTP and edit files.

Thank you!

Score:0
in flag

The containers need the ownership of the directories for the user that is used in the container. This depends on the image, every creator can choose which user he wants to use in the container, since the container is isolated.

When you run docker inspect containername you can find this in the configuration:

"Config": {
         "User": "1001:1002",

In this case, the application in the container runs with the user 1001 and the group 1002. For that you would need to run chown 1001:1002 on the folder you mount as a volume into your container.

If the value for User is empty, it runs as root. In that case the permissions won't matter.

zkvvoob avatar
kp flag
Thank you, this is very informative! Please me understand something else: what is the best practice - do I add a `docker:docker` user:group and set it as both the running user for each container and then the owner of the folder? And then add my user to the `docker` group so that I could browse/edit?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.