grocy-docker
grocy-docker copied to clipboard
Multiple users with own household
Hello
I have read here that it is possible to use multiple databases with one instance by setting the environment variable GROCY_DATAPATH. I use Apache as a reverse proxy and Grocy runs in a docker container.
How do I need to configure Apache to manage multiple households with one Grocy instance?
I told a friend about Grocy and she wants to use it for her household. Since we have separate households, adding her as a user is not enough.
But I also don't want to run multiple Grocy instances (if it can be avoided).
I am grateful for tips and suggestions.
Many greetings Tim
Hi @Poldi1977! - my apologies for the delayed response here.
I think I understand your use case - you'd like to continue running a single instance of containerized grocy
, and to store your own data and your friend's data in separate compartments within that -- as supported by the GROCY_DATAPATH
feature.
A few questions to help provide guidance:
- Can you check/confirm whether you're running
linuxserver/grocy
-based orgrocy/...
-based images within docker? - Are you running
grocy
by using adocker-compose.yml
file? - How comfortable are you with modifying and maintaining a few changes to the "official" images in order to support this case?
And something that you may already have considered, but that I'll mention anyway: how to maintain and share backups is likely worth thinking about.
Hello @jayaddison
Thank you for your answer.
- I use the grocy/ based docker image
- Exactly, I use a docker-compose.yml file
- I think I should be able to manage this
I create backups of grocy
on a daily basis.
Ok, thanks! This could be an incomplete guide, so please let me know if you find problems when attempting it, but this is my evaluation & recommendation so far:
Background
- We can configure
GROCY_DATAPATH
either by environment variable or server variable- For this issue, a server variable seems more suitable because there is only a single application running (and so we can only define environment variables for it once)
-
grocy
currently runs as an PHP-FPM application within the container -- meaning that the client that talks to it (grocy/frontend
in this case) needs to talk the FastCGI protocol. Currently that is configured in part of thefrontend
container'snginx
config.
With any approach, it's recommended to:
- Fork a copy of this repository because some configuration changes will be required
- Take a recent backup of data from your volume, because there is a risk of problems while attempting the changes
Option 1 (single-grocy)
- Choose directory names for yourself and your friend -- perhaps usernames
- Stop the running
grocy
container - Consider taking Apache (or the site(s) forwarding to your
grocy
instance within Apache) offline - Locate and edit the
app-db
volume - Move your data into a subdirectory, using your selected directory name
- Configure
fastcgi_param GROCY_DATAPATH ...
within the nginx configuration- This step will have to be somewhat customized for your situation - either the URL, hostname, headers, or some other Apache configuration is going to need to communicate the input that decides how to select the relevant datapath directory name.
- Rebuild the
grocy
containers usingdocker-compose build
- Start the containers and test connectivity outside Apache
- For example, using
curl
or similar to send the appropriate request URLs / headers / auth details that your customnginx
configuration expects - This might create a few empty / test directories depending on how you do it, so you may want to restore-from-backup after testing
- For example, using
- Restore connectivity from Apache
There is some interesting overlap with the functionality discussed in https://github.com/grocy/grocy#1746. If there were a reliable way to have a $user
variable provided to nginx
then this could be included in the default configuration -- but until then we have the challenge that authentication tends to be different in almost every environment.
Option 2 (multi-grocy)
If you run remove the single-instance requirement, and use multiple instances of grocy
, there are some benefits and drawbacks.
On the plus side:
- Custom image builds should not be required (since no
nginx
customization is taking place) - Co-ordination between Apache and
nginx
might be easier (map to a destination port, instead of potentially providing other selection criteria that annginx
configuration can read)
However, some editing of this repository's contents would still be required:
- Editing
docker-compose.yml
to run and expose ports for multiple instances of the application -- and to define at least one extra volume - Checking/editing your backup solution to ensure that both
backend
data volumes are included
Disclaimer / Feedback I haven't attempted this myself, so "your mileage may vary" - please be careful with any changes!
If you find a way to achieve this that is opt-in and generalizes to other users, I'll be happy to take a look at that (either as a pull request or in a branch) and to consider bringing the changes into here "upstream" for others and to reduce your maintenance.
Closing as maybe-resolved; please feel free to reopen if there's more to figure out here. Would be great to hear your feedback (here / blog post!) if you managed to get a multi-household system deployed, too.