After much research and fiddling around I have learned that Docker Desktop on Linux is causing the permission issues.
Docker Desktop on Linux runs a virtual machine and the containers will run inside that virtual machine. In that case you can’t just mount the host folder the same way into the containers, because you need to mount it first into the virtual machine.
So, as someone who is by all means not a Docker expert, I see two ways of addressing this issue:
(1) Ditch Docker Desktop on Linux and run Docker natively instead
This seems to be the most sustainable solution as I see that the discourse container seems to be designed to be used like that. I’m only hesistant because then I have to remember all the commands to manage my images, containers and resources. And, being a frontent dev, I’d rather fancy an UI to manage stuff. But I guess I have to approach this as an investment to learn more about Docker.
(2) Change ownership of the folders mounted into the container
I managed to get this approach to work and successfully run Discourse locally from Docker Desktop, however I do see a bunch of warnings in the Terminal and therefore I’m not sure how sustainable this solution is in the long run.
This involves several steps:
Step 1: Clone the Repo
$ git clone https://github.com/discourse/discourse.git
$ cd discourse
Step 2: Initialize Container
From within the cloned discourse folder on the host machine, execute:
What does it do? See here.
Important: Omit the
--init flag so that nothing will be done after the container creation.
Step 3: Change owner of folders
The discourse user within the docker container has the id
1000. This guide assumes that your host machine’s user also has that same id. It might not break things if your host machine’s user has a different id, but I cannot test this and therefore can’t speak for this situation. You can find out your id by executing
echo $UID in a linux terminal.
From your host machine, execute:
# open a shell in the docker container
# you should already be in /src, bug just for good measure:
$ cd /src
# change the owner of /src to the discourse user and group
$ chown 1000:1000 .
# change the owner of all files and folders within /src to the discourse user and group (non-recursively)
$ chown 1000:1000 *
# recursively change the owner of almost all subfolders to the discourse user and group
# basically all folders except 'database', because that one belongs to the 'postgres' user and group
$ chown -R 1000:1000 app bin config d db docs documentation images lib log plugins public script spec test vendor
# verify that it has worked, should show the discourse user and group now
$ ls -l
# leave the container
Step 4: Continue as usual
Continue setting up the container and starting Discourse by executing the following from your host machine:
# install gems
$ d/bundle install
# migrate database
$ d/rake db:migrate
$ RAILS_ENV=test d/rake db:migrate
# create admin user
$ d/rake admin:create
# In one terminal:
# And in a separate terminal
I faced some warnings like this:
fatal: detected dubious ownership in repository at '/src'
Which comes from the Docker Desktop on Linux virtualization thing.
Do ignore these warnings, from your host machine, execute:
d/exec git config --global --add safe.directory /src
Why does Docker Desktop for Linux run a VM?