samschott / maestral

Open-source Dropbox client for macOS and Linux
https://maestral.app
MIT License
3.12k stars 64 forks source link

Support running under other UID/GID/user/group #972

Open 6XGate opened 1 year ago

6XGate commented 1 year ago

Is your feature request related to a problem? Please describe. Requiring UID 1000 for docker is not possible due to our admin's policy.

Describe the solution you'd like Allow the container to run with a different UID / GID.

6XGate commented 1 year ago

Not sure if this is the cause the this issue.

/dropbox $ maestral start
Traceback (most recent call last):
  File "/usr/local/bin/maestral", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.10/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/maestral/cli/common.py", line 35, in wrapper
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/maestral/cli/cli_core.py", line 177, in start
    if is_running(config_name):
  File "/usr/local/lib/python3.10/site-packages/maestral/daemon.py", line 325, in is_running
    return maestral_lock(config_name).locked()
  File "/usr/local/lib/python3.10/site-packages/maestral/daemon.py", line 282, in maestral_lock
    path = get_runtime_path("maestral")
  File "/usr/local/lib/python3.10/site-packages/maestral/utils/appdirs.py", line 201, in get_runtime_path
    return to_full_path(runtime_path, subfolder, filename, create)
  File "/usr/local/lib/python3.10/site-packages/maestral/utils/appdirs.py", line 30, in to_full_path
    os.makedirs(path, exist_ok=True)
  File "/usr/local/lib/python3.10/os.py", line 215, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "/usr/local/lib/python3.10/os.py", line 225, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/.cache'
allofmex commented 4 months ago

Here a little workarround (!) to run Maestral with UID different than 1000:

Create own Dockerfile (based on original Dockerfile)

FROM maestraldbx/maestral

####  set your target UID here #####
ARG UID=2000

# switch back to root to allow deluser/adduser
USER root

# remove old dropbox user
RUN deluser dropbox

# re-add dropbox user with your target UID
RUN adduser -D -u ${UID} -h /dropbox dropbox
RUN chown dropbox:dropbox /dropbox

# switch back to run user
USER dropbox

For initial setup

docker build -t my/maestral .
run -it -v /mnt/dropbox:/dropbox my/maestral ash

$ maestral start

Running Maestral daemon

docker run \
  -d \
  --name maestral \
  --rm \
  -v /mnt/dropbox:/dropbox \
  my/maestral

/mnt/dropbox will be accessed as UID 2000 now