Jump to content

[GUIDE] Set up the OneDrive Client for Linux (abraunegg) as Docker container


Recommended Posts

I am a new user of Unraid and Docker and was looking for an alternative to Synology Cloud Sync, which I used to keep all my family's Onedrive files as harcopy on my previous NAS (multiple accounts). I was therefor not looking for an app like Duplicati/Duplicay to spread my files even further over the cloud, but to get my files back from the cloud and keep them synchronized. For this purpose I decided to run the Onedrive Client for Linux in a separate docker container for different Onedrive accounts on my Unraid install, which seems to work quite well. Below my beginners guide for how to set this up with docker compose following this guide

Requirements:

  • Docker compose installed
  • Dynamix File Manager installed (helpful)


Step 1:
In the Unraid WebUI open the terminal and type ‘id username’ for every user with onedrive account you want to install a Onedrive container for and write down the UID and GID for these users.

 

Step 2:
Add a share called ‘onedrive’ (or choose your own name). Optionally enable cache, select preferred disk(s) and decide if you want to export the share.

 

Step 3:
If you are planning to use multiple containers/accounts, create subfolders for every user as well in the just created onedrive folder (/onedrive/userA, /onedrive/userB, etc.). Do this before running the container later on.

 

Step 4:
Create a ‘onedrive’ folder under /mnt/user/appdata/ and again create subfolders (userA, userB etc.) for different users

 

Step 5:
Go to the Docker tab, scroll down to Compose and press ‘Add new stack’

Step 6:
Type a project name (for example Onedrive-userA) and press ‘OK’ and again ‘OK’ after success

Step 7:
Click on the cog-wheel of the new created stack and press ‘Edit stack’ followed by ‘Compose file’

 

Step 8:
Past in the composer file below:

version: "3.7"
services:
    onedrive:
        image: driveone/onedrive:latest
        container_name: Onedrive-userA
        stdin_open: true # docker run -i
        tty: true        # docker run -t
        restart: unless-stopped
        environment:
            - ONEDRIVE_UID=1001
            - ONEDRIVE_GID=100
        volumes: 
            - /mnt/user/appdata/onedrive/userA:/onedrive/conf/
            - /mnt/user/onedrive/userA:/onedrive/data

 

Step 9:
Before saving, make the following changes to the composer file:

·       Change the container name in a name of your liking, for example Onedrive_UserA, Onedrive_UserB.

·       Change the UID and GID to the correct values for the user, as found in step 1

·       Under volumes change the path left from the colon to the correct config and data folder (so ‘/mnt/user/appdata/onedrive/userA’ and ‘/mnt/user/onedrive/userA’ if the example above has been followed. Don't touch the values right from the colon.

·       Optionally, if you created your custom network for docker containers, you can add the network settings below and change 'nameofyournetwork' to the name of your network. Otherwise a new network (container_name_default) is created. Example:

version: "3.7"
services:
    onedrive:
        image: driveone/onedrive:latest
        container_name: Onedrive-userA
        stdin_open: true # docker run -i
        tty: true        # docker run -t
        restart: unless-stopped
        environment:
            - ONEDRIVE_UID=1001
            - ONEDRIVE_GID=100
        volumes: 
            - /mnt/user/appdata/onedrive/userA:/onedrive/conf/
            - /mnt/user/onedrive/userA:/onedrive/data
        networks:
            - proxy
networks:
  proxy:
    external: true
    name: nameofyournetwork   

 

Step 10:
Press ‘save changes’

 

Step 11 (optional):
If you want to add an icon to your docker container (otherwise you’ll see a questionmark), press the cog-wheel again, select ‘edit stack’ and select UI labels. On the internet find a link to the icon of your choosing (for example from Onedrive’s wiki) and past the link in this field. This can be done later on as well (by updating the stack). Press ‘OK’ when done.

 

Step 12:
Press ‘Compose up’ and press ‘Done’ when it is done.

 

A new container is now created and running, but the Onedrive Client still needs to be connected to your Microsoft account with the following steps:

Step 13:
Stop the new container

 

Step 14:

In the right upper corner of the docker page, switch over from ‘Basic view’ to ‘Advanced view’. Now you can see the Container ID for your newly made container (for example 72409c107bd0). Copy this number.

 

Step 15:
Open the Unraid terminal and enter:

docker start your_container_id --interactive

Use right mouse and paste to paste your container ID in the terminal.


Step 16:
After entering the command and pressing enter, the container starts in an interactive mode and a link to Microsoft is shown in the terminal. You open this link by clicking on it and log in with the Microsoft credentials of the onedrive account you want to add. If successful, a blank page is shown. Copy the full address of this page and past it (right mouse and paste) in the terminal as the response URL and press enter. If the link is accepted, the client immediately starts downloading your files.

 

Step 17:
You can close the terminal, restart the container and everything should be working from now on.

 

Step 18:

Repeat step 5-17 for every account you want to add. For some reason you need to select a different Icon URL for every new container you want to add.

 

 

In case you encounter permission errors when trying to access your downloaded files when using onedrive multiple accounts, check the solution below by Cholzer:

 

Edited by BVersluis
Additional information
  • Like 1
  • Thanks 1
Link to comment
  • 2 weeks later...
  • 3 weeks later...
On 1/25/2023 at 4:10 AM, Guo Jiacheng said:

How can I change the new created file permission to 755? Right now, to share between users, I have repeatedly change new synced file permission to 755. The default permission is 500 ?

Yes, default is 500. Every Unraid user with his/her own UID has only access to his/her files Onedrive by default. If one Unraid user has multiple Onedrive accounts, you could use the same UID and have access to all files, but by default only the owner of the files (container) has access. To my knowledge - and my Docker knowledge is very limited - there is no easy way to change this in docker (in combination with mounted volumes). Depending on your needs, one 'solution' could be to create an Unraid user (UID) for all Onedrive accounts you want to share files between and use this account to access your files. Perhaps this might be of help.

Edited by BVersluis
Link to comment

Looking into the docs for the app on github, there does appear to be a solution y creating a config file. I have created this file in the config directory as mapped in the docker config, but when opening the console and running "onedrive --display-config" it doesn't appear to show as seems it may have another path mapped? Is this an issue anoyone else has come across?

This is actually of more benefit to me, not just for the permissions, but by also excluding some directories from sync

 

image.png.3aac371a38b3de2d7b7e50a52511cad8.png

 

Output:

# onedrive --display-config
onedrive version                             = v2.4.23
Config path                                  = /root/.config/onedrive
Config file found in config path             = false
Config option 'sync_dir'                     = /root/OneDrive
Config option 'enable_logging'               = false
Config option 'log_dir'                      = /var/log/onedrive/
Config option 'disable_notifications'        = false
Config option 'min_notify_changes'           = 5
Config option 'skip_dir'                     = 
Config option 'skip_dir_strict_match'        = false
Config option 'skip_file'                    = ~*|.~*|*.tmp
Config option 'skip_dotfiles'                = false
Config option 'skip_symlinks'                = false
Config option 'monitor_interval'             = 300
Config option 'monitor_log_frequency'        = 6
Config option 'monitor_fullscan_frequency'   = 12
Config option 'read_only_auth_scope'         = false
Config option 'dry_run'                      = false
Config option 'upload_only'                  = false
Config option 'download_only'                = false
Config option 'local_first'                  = false
Config option 'check_nosync'                 = false
Config option 'check_nomount'                = false
Config option 'resync'                       = false
Config option 'resync_auth'                  = false
Config option 'cleanup_local_files'          = false
Config option 'classify_as_big_delete'       = 1000
Config option 'disable_upload_validation'    = false
Config option 'bypass_data_preservation'     = false
Config option 'no_remote_delete'             = false
Config option 'remove_source_files'          = false
Config option 'sync_dir_permissions'         = 700
Config option 'sync_file_permissions'        = 600
Config option 'space_reservation'            = 52428800
Config option 'application_id'               = 
Config option 'azure_ad_endpoint'            = 
Config option 'azure_tenant_id'              = common
Config option 'user_agent'                   = 
Config option 'force_http_11'                = false
Config option 'debug_https'                  = false
Config option 'rate_limit'                   = 0
Config option 'operation_timeout'            = 3600
Config option 'sync_root_files'              = false
Selective sync 'sync_list' configured        = false
Config option 'sync_business_shared_folders' = false
Business Shared Folders configured           = false
Config option 'webhook_enabled'              = false

Link to comment
7 hours ago, isaacgrant85 said:

Looking into the docs for the app on github, there does appear to be a solution y creating a config file. I have created this file in the config directory as mapped in the docker config, but when opening the console and running "onedrive --display-config" it doesn't appear to show as seems it may have another path mapped? Is this an issue anoyone else has come across?

This is actually of more benefit to me, not just for the permissions, but by also excluding some directories from sync

 

image.png.3aac371a38b3de2d7b7e50a52511cad8.png

 

Output:

# onedrive --display-config
onedrive version                             = v2.4.23
Config path                                  = /root/.config/onedrive
Config file found in config path             = false
Config option 'sync_dir'                     = /root/OneDrive
Config option 'enable_logging'               = false
Config option 'log_dir'                      = /var/log/onedrive/
Config option 'disable_notifications'        = false
Config option 'min_notify_changes'           = 5
Config option 'skip_dir'                     = 
Config option 'skip_dir_strict_match'        = false
Config option 'skip_file'                    = ~*|.~*|*.tmp
Config option 'skip_dotfiles'                = false
Config option 'skip_symlinks'                = false
Config option 'monitor_interval'             = 300
Config option 'monitor_log_frequency'        = 6
Config option 'monitor_fullscan_frequency'   = 12
Config option 'read_only_auth_scope'         = false
Config option 'dry_run'                      = false
Config option 'upload_only'                  = false
Config option 'download_only'                = false
Config option 'local_first'                  = false
Config option 'check_nosync'                 = false
Config option 'check_nomount'                = false
Config option 'resync'                       = false
Config option 'resync_auth'                  = false
Config option 'cleanup_local_files'          = false
Config option 'classify_as_big_delete'       = 1000
Config option 'disable_upload_validation'    = false
Config option 'bypass_data_preservation'     = false
Config option 'no_remote_delete'             = false
Config option 'remove_source_files'          = false
Config option 'sync_dir_permissions'         = 700
Config option 'sync_file_permissions'        = 600
Config option 'space_reservation'            = 52428800
Config option 'application_id'               = 
Config option 'azure_ad_endpoint'            = 
Config option 'azure_tenant_id'              = common
Config option 'user_agent'                   = 
Config option 'force_http_11'                = false
Config option 'debug_https'                  = false
Config option 'rate_limit'                   = 0
Config option 'operation_timeout'            = 3600
Config option 'sync_root_files'              = false
Selective sync 'sync_list' configured        = false
Config option 'sync_business_shared_folders' = false
Business Shared Folders configured           = false
Config option 'webhook_enabled'              = false

The config path you map during setup is the (user) location were the Microsoft account details will be saved and is not the same as the root location (root/.config/onedrive) where that configuration file should be saved. I just tried using the method Abraunegg describes here and you can make this working, but I don't know if these changes are preserved during container updates. In the current situation, if you remove the container but leave the config (and data) folder, everything will work again directly if you reinstall the container and choose the same config and data location as before. This won't be the case for changes made within the container below. Even though the config file works as intended, the permission issues you mentioned before will probably not be solved for all users by changing the permissions in the config file.

 

To add the config file to your container:

1. Start the container and open the container console

2. Go to the root directory (cd /root/)

3. In order to be able to edit to get the config file and edit the config file in the container, you have to install wget and nano by entering and approving the following commands:

apt-get update
apt-get install nano
apt-get install -y wget

4. Use the following commands from Abrauneggs documentation to create the correct folder, download the config file and open the config file in Nano to make the necessary changes:

mkdir -p ~/.config/onedrive
wget https://raw.githubusercontent.com/abraunegg/onedrive/master/config -O ~/.config/onedrive/config
nano ~/.config/onedrive/config

5. Make the changes you want in Nano, safe and restart the container for the changes to take effect. With the --display-config function after restart you can check if everything works.

Link to comment
On 1/31/2023 at 4:48 PM, BVersluis said:

To add the config file to your container:

1. Start the container and open the container console

2. Go to the root directory (cd /root/)

3. In order to be able to edit to get the config file and edit the config file in the container, you have to install wget and nano by entering and approving the following commands:

apt-get update
apt-get install nano
apt-get install -y wget

4. Use the following commands from Abrauneggs documentation to create the correct folder, download the config file and open the config file in Nano to make the necessary changes:

mkdir -p ~/.config/onedrive
wget https://raw.githubusercontent.com/abraunegg/onedrive/master/config -O ~/.config/onedrive/config
nano ~/.config/onedrive/config

5. Make the changes you want in Nano, safe and restart the container for the changes to take effect. With the --display-config function after restart you can check if everything works.

 

I tried that but these changes do not survive a docker restart. In fact you even have to reinstall nano again after restarting the docker.

Here is how I fixed the permission issue:

1. stop the onedrive docker
2. go to the folder you selected for the "Configuration:" of the docker

3. download the original config file from here https://raw.githubusercontent.com/abraunegg/onedrive/master/config

4. remove the # ONLY infront of the settings you want to change, and change the setting accordingly (i.e. sync_dir_permissions = "777" and sync_file_permissions = "777")

5. do not touch any of the other settings you dont want to change!
6. (optional) delete the items.sqlite3, items.sqlite3-wal and all your allready synced files to start fresh

6. start the docker
7. all newly synced files will have their permissions set to drwxrwxrwx / -rwxrwxrwx

Link to comment
  • 2 weeks later...
On 1/22/2023 at 3:40 PM, PeterPan said:

The great CA Maintainer BVersluis just uploaded a great working application. Just search in the shop 🙂

I tried install this app but I'm with this error.

ERROR: Microsoft OneDrive API returned an error with the following message:
  Error Message:    Timeout was reached on handle 5562906E6550

Link to comment
  • 4 weeks later...
  • 10 months later...

Thank you so much for this guide! Worked straight away and currently downloading everything :)

Will need to play around a bit to see how it will behave, if i share the synced onedrive folder on the local LAN and access it from my regular pc.

But i suppose that's how you have it running, too?

Edited by Jabberwocky
Link to comment

Yes, that should work. I'm actually no longer using the linux client. I was missing some other synology apps as well and since I found a guide at this forum to install DSM as a VM, I'm running DSM on my unraid server and started using the Synology cloud sync again. 

Link to comment
  • 2 weeks later...

Shared the synced onedrive share with smb in the local network and it's working fine so far.

Just wondering, is the Synology cloud sync more stable than running onedrive directly on unraid in the docker container? Or simply to have all apps in one place?

 

One more question - is there a way to set the update interval for onedrive? Currently it will scan the onedrive folder every 300 seconds (5min) for changes.

As i dont need to run constantly in the background, once per day (i.e. at midnight) would be enough in my setup.

 

 

Link to comment

I have never had stability issues with neither cloud sync or the linux client, but cloud sync is more user friendly, easy to sync multiple accounts (and not only for onedrive). Disadvantage is that as it is running as a VM, only the VM has access to the content of the Vdisks and you need the VM to be running att all time to access the files on your network. DSM doesn't use that many resources when idle, so no problem for me. 

 

I used the 'user-scripts' plugin to run the docker container for only 1 hour each night. I don't know if these options are available within the client (synology cloud sync has).

Link to comment

Hmm i agree, a nice user interface to sync to different services would be really nice to have. 

I currently don't have that many services running locally so an extra VM to run DSM just to run CloudSync feels a bit like an overhead.

 

But good to hear, that you used the "user-scripts" plugin - starting & stopping the docker container with a script was my next idea, too :)

As a beginner with scripting, I assume your script looked something like this?

 

#!/bin/bash
#Start Docker
docker start Onedrive_User1
#Delay before issuing Stop
sleep 2h
#Stop Docker
docker stop Onedrive_User1

 

Edited by Jabberwocky
Link to comment

So after a few runs the script works nicely with a cron based schedule. I found this website helpfull when it comes to the cron schedule: https://crontab.guru/

Really nice to have the logfile right next to the script so there is no need for searching on the CLI :)


 

Quote

 

Script Starting Feb 08, 2024 16:23.29
Full logs for this script are available at /tmp/user.scripts/tmpScripts/onedrive_schedule/log.txt
Onedrive_User1
Onedrive_User1
Script Finished Feb 08, 2024 17:23.32
Full logs for this script are available at /tmp/user.scripts/tmpScripts/onedrive_schedule/log.txt

 

Script Starting Feb 09, 2024 00:00.01
Full logs for this script are available at /tmp/user.scripts/tmpScripts/onedrive_schedule/log.txt
Onedrive_User1
Onedrive_User1
Script Finished Feb 09, 2024 01:00.04
Full logs for this script are available at /tmp/user.scripts/tmpScripts/onedrive_schedule/log.txt

 

Script Starting Feb 10, 2024 00:00.01
Full logs for this script are available at /tmp/user.scripts/tmpScripts/onedrive_schedule/log.txt
Onedrive_User1
Onedrive_User1
Script Finished Feb 10, 2024 01:00.08
Full logs for this script are available at /tmp/user.scripts/tmpScripts/onedrive_schedule/log.txt

 

 

Another option would be to create two scripts - one for starting and one for stopping the docker container but i just leave it in one script for now.

Link to comment
  • 2 weeks later...
  • 1 month later...

Just changed my OneDrive Password so the access token in the OneDrive installation was not accepted anymore.

In the logs it showed up as:

 

ERROR: Microsoft OneDrive API returned an error with the following message:
  Error Message:    HTTP request returned status code 400 (Bad Request)
  Error Reason:     AADSTS70000: The user could not be authenticated as the grant is expired. The user must sign in again. Trace ID: XXXXXXX Correlation ID: XXXXXXX Timestamp: 2024-04-20 09:07:31Z

ERROR: Microsoft OneDrive API returned an error with the following message:
  Error Message:    HTTP request returned status code 401 ()
  Error Reason:     Access token is empty.
  Error Timestamp:  2024-04-20T09:07:31
  API Request ID:   XXXXXX

ERROR: Check your configuration as your refresh_token may be empty or invalid. You may need to issue a --reauth and re-authorise this client.

 

 

The old token can be removed / archived like this (adjust the path to the token accordingly to match your setup)

 

mv /mnt/user/appdata/onedrive/username/refresh_token /mnt/user/appdata/onedrive/username/refresh_token.backup

 

Afterwards start the re-authorization at STEP 13 of the guide again

 

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...