2021-03-05 21:07:54 +01:00
# Run the OneDrive Client for Linux under Docker
This client can be run as a Docker container, with 3 available options for you to choose from:
2022-06-02 09:38:02 +02:00
2022-06-02 10:58:13 +02:00
| Container Base | Docker Tag | Description | x86_64 | ARMHF | AARCH64 |
|----------------|-------------|----------------------------------------------------------------|:------:|:-----:|:-------:|
| Alpine Linux | edge-alpine | Docker container based on Apline 3.16 using 'master' |✔|❌|✔|
| Alpine Linux | alpine | Docker container based on Apline 3.16 using latest release |✔|❌|✔|
| Debian | edge-debian | Docker container based on Debian Bullseye using 'master' |✔|✔|✔|
| Debian | debian | Docker container based on Debian Bullseye using latest release |✔|✔|✔|
| Debian | edge | Docker container based on Debian Bullseye using 'master' |✔|✔|✔|
2022-06-03 23:24:28 +02:00
| Fedora | latest | Docker container based on Debian Bullseye using latest release |✔|✔|✔|
| Fedora | edge-fedora | Docker container based on Fedora 36 using 'master' |✔|✔|✔|
| Fedora | fedora | Docker container based on Fedora 36 using latest release |✔|✔|✔|
2018-12-04 01:59:03 +01:00
2021-03-05 21:07:54 +01:00
These containers offer a simple monitoring-mode service for the OneDrive Client for Linux.
The instructions below have been validated on:
* Red Hat Enterprise Linux 8.x
2022-06-02 09:38:02 +02:00
* Ubuntu Server 22.04
2021-03-05 21:07:54 +01:00
2022-06-02 09:38:02 +02:00
The instructions below will utilise the 'edge' tag, however this can be substituted for 'edge-alpine', 'edge-debian' or 'edge-fedora' if desired.
2018-12-04 01:59:03 +01:00
2019-11-20 21:02:56 +01:00
## Basic Setup
2021-03-05 21:07:54 +01:00
### 0. Install docker using your distribution platform's instructions
1. Ensure that SELinux has been disabled on your system. A reboot may be required to ensure that this is correctly disabled.
2. Install Docker as per requried for your platform
3. Obtain your normal, non-root user UID and GID by using the `id` command
4. As your normal, non-root user, ensure that you can run `docker run hello-world` *without* using `sudo`
2019-01-22 02:31:57 +01:00
2021-03-05 21:07:54 +01:00
Once the above 4 steps are complete and you can successfully run `docker run hello-world` without sudo, only then proceed to 'Pulling and Running the Docker Image'
2019-01-22 02:31:57 +01:00
2021-03-05 21:07:54 +01:00
## Pulling and Running the Docker Image
2019-01-22 02:34:44 +01:00
### 1. Pull the image
2019-01-06 17:02:58 +01:00
```bash
2022-06-02 10:58:13 +02:00
docker pull driveone/onedrive:latest
2018-12-04 01:59:03 +01:00
```
2019-01-23 02:20:52 +01:00
2021-03-05 21:07:54 +01:00
**NOTE:** SELinux context needs to be configured or disabled for Docker to be able to write to OneDrive host directory.
2018-12-04 01:59:03 +01:00
2019-11-20 21:02:56 +01:00
### 2. Prepare config volume
2021-03-05 21:07:54 +01:00
The Docker container requries 2 Docker volumes:
* Config Volume
* Data Volume
2019-01-22 02:31:57 +01:00
2021-03-05 21:07:54 +01:00
Create the config volume with the following command:
2019-01-06 00:14:49 +01:00
```bash
2019-01-25 15:03:40 +01:00
docker volume create onedrive_conf
2019-01-22 02:31:57 +01:00
```
2018-12-04 01:59:03 +01:00
2019-11-20 21:02:56 +01:00
This will create a docker volume labeled `onedrive_conf` , where all configuration of your onedrive account will be stored. You can add a custom config file and other things later.
2019-01-22 02:31:57 +01:00
2021-03-05 21:07:54 +01:00
The second docker volume is for your data folder and is created in the next step. This volume needs to be a path to a directory on your local filesystem, and this is where your data will be stored from OneDrive. Keep in mind that:
2019-01-22 09:37:47 +01:00
2021-03-05 21:07:54 +01:00
* The owner of this specified folder must not be root
* The owner of this specified folder must have permissions for its parent directory
2019-01-23 02:20:52 +01:00
2021-03-05 21:07:54 +01:00
**NOTE:** Issues occur when this target folder is a mounted folder of an external system (NAS, SMB mount, USB Drive etc) as the 'mount' itself is owed by 'root'. If this is your use case, you *must* ensure your normal user can mount your desired target without having the target mounted by 'root'. If you do not fix this, your Docker container will fail to start with the following error message:
```bash
ROOT level privileges prohibited!
```
2019-01-22 02:31:57 +01:00
2019-01-22 02:34:44 +01:00
### 3. First run
2021-03-05 21:07:54 +01:00
The 'onedrive' client within the Docker container needs to be authorized with your Microsoft account. This is achieved by initially running docker in interactive mode.
2019-01-22 02:31:57 +01:00
2021-03-07 19:44:22 +01:00
Run the docker image with the commands below and make sure to change `ONEDRIVE_DATA_DIR` to the actual onedrive data directory on your filesystem that you wish to use (e.g. `"/home/abraunegg/OneDrive"` ).
2021-03-05 21:07:54 +01:00
```bash
export ONEDRIVE_DATA_DIR="${HOME}/OneDrive"
mkdir -p ${ONEDRIVE_DATA_DIR}
2021-10-06 10:17:33 +02:00
docker run -it --name onedrive -v onedrive_conf:/onedrive/conf \
-v "${ONEDRIVE_DATA_DIR}:/onedrive/data" \
2021-10-30 22:47:43 +02:00
-e "ONEDRIVE_UID=${ONEDRIVE_UID}" \
-e "ONEDRIVE_GID=${ONEDRIVE_GID}" \
2022-06-02 10:58:13 +02:00
driveone/onedrive:latest
2021-03-05 21:07:54 +01:00
```
**Important:** The 'target' folder of `ONEDRIVE_DATA_DIR` must exist before running the Docker container, otherwise, Docker will create the target folder, and the folder will be given 'root' permissions, which then causes the Docker container to fail upon startup with the following error message:
2019-01-22 02:31:57 +01:00
```bash
2021-03-05 21:07:54 +01:00
ROOT level privileges prohibited!
```
2021-10-06 23:13:00 +02:00
**NOTE:** It is also highly advisable for you to replace `${ONEDRIVE_UID}` and `${ONEDRIVE_GID}` with your actual UID and GID as specified by your `id` command output to avoid any any potential user or group conflicts.
2021-03-05 21:07:54 +01:00
**Example:**
2021-10-06 23:13:00 +02:00
```bash
2021-10-06 10:17:33 +02:00
export ONEDRIVE_UID=`id -u`
export ONEDRIVE_GID=`id -g`
2021-10-06 23:13:00 +02:00
export ONEDRIVE_DATA_DIR="${HOME}/OneDrive"
mkdir -p ${ONEDRIVE_DATA_DIR}
2021-10-30 22:47:43 +02:00
docker run -it --name onedrive -v onedrive_conf:/onedrive/conf \
-v "${ONEDRIVE_DATA_DIR}:/onedrive/data" \
-e "ONEDRIVE_UID=${ONEDRIVE_UID}" \
-e "ONEDRIVE_GID=${ONEDRIVE_GID}" \
2022-06-02 10:58:13 +02:00
driveone/onedrive:latest
2018-12-04 01:59:03 +01:00
```
2019-01-22 02:31:57 +01:00
2021-03-05 21:07:54 +01:00
When the Docker container successfully starts:
* You will be asked to open a specific link using your web browser
* Login to your Microsoft Account and give the application the permission
* After giving the permission, you will be redirected to a blank page
* Copy the URI of the blank page into the application prompt to authorise the application
2019-01-22 02:31:57 +01:00
2021-03-05 21:07:54 +01:00
Once the 'onedrive' application is authorised, the client will automatically start monitoring your `ONEDRIVE_DATA_DIR` for data changes to be uploaded to OneDrive. Files stored on OneDrive will be downloaded to this location.
2019-01-22 02:31:57 +01:00
2021-03-05 21:07:54 +01:00
If the client is working as expected, you can detach from the container with Ctrl+p, Ctrl+q.
2019-01-22 02:31:57 +01:00
2021-03-05 21:07:54 +01:00
### 4. Docker Container Status, stop, and restart
2019-11-20 21:02:56 +01:00
Check if the monitor service is running
2019-01-23 02:20:52 +01:00
2019-01-06 17:02:58 +01:00
```bash
2018-12-04 01:59:03 +01:00
docker ps -f name=onedrive
```
2019-01-22 02:31:57 +01:00
Show monitor run logs
2019-01-23 02:20:52 +01:00
2019-01-06 17:02:58 +01:00
```bash
2018-12-04 01:59:03 +01:00
docker logs onedrive
```
2019-01-22 02:31:57 +01:00
Stop running monitor
2019-01-23 02:20:52 +01:00
2019-01-06 17:02:58 +01:00
```bash
2018-12-04 01:59:03 +01:00
docker stop onedrive
```
2019-01-22 02:31:57 +01:00
Resume monitor
2019-01-23 02:20:52 +01:00
2019-01-06 17:02:58 +01:00
```bash
2018-12-04 01:59:03 +01:00
docker start onedrive
```
2019-01-22 02:31:57 +01:00
2021-03-05 21:07:54 +01:00
Remove onedrive Docker container
2019-01-23 02:20:52 +01:00
2019-01-06 17:02:58 +01:00
```bash
2018-12-04 01:59:03 +01:00
docker rm -f onedrive
```
2019-11-20 21:02:56 +01:00
## Advanced Setup
2019-01-22 02:31:57 +01:00
2020-07-03 21:34:42 +02:00
### 5. Docker-compose
Also supports docker-compose schemas > 3.
2021-03-05 21:07:54 +01:00
In the following example it is assumed you have a `ONEDRIVE_DATA_DIR` environment variable and a `onedrive_conf` volume.
2020-07-03 21:34:42 +02:00
However, you can also use bind mounts for the configuration folder, e.g. `export ONEDRIVE_CONF="${HOME}/OneDriveConfig"` .
```
version: "3"
services:
onedrive:
2022-06-02 10:58:13 +02:00
image: driveone/onedrive:latest
2020-07-03 21:34:42 +02:00
restart: unless-stopped
environment:
- ONEDRIVE_UID=${PUID}
- ONEDRIVE_GID=${PGID}
volumes:
- onedrive_conf:/onedrive/conf
2021-03-05 21:07:54 +01:00
- ${ONEDRIVE_DATA_DIR}:/onedrive/data
2020-07-03 21:34:42 +02:00
```
Note that you still have to perform step 3: First Run.
### 6. Edit the config
2021-03-05 21:07:54 +01:00
The 'onedrive' client should run in default configuration, however you can change this default configuration by placing a custom config file in the `onedrive_conf` docker volume. First download the default config from [here ](https://raw.githubusercontent.com/abraunegg/onedrive/master/config )
2019-01-23 05:46:41 +01:00
Then put it into your onedrive_conf volume path, which can be found with:
```bash
docker volume inspect onedrive_conf
```
2019-01-22 09:37:47 +01:00
2019-11-20 21:02:56 +01:00
Or you can map your own config folder to the config volume. Make sure to copy all files from the docker volume into your mapped folder first.
2019-01-22 09:37:47 +01:00
2020-11-03 02:08:16 +01:00
The detailed document for the config can be found here: [Configuration ](https://github.com/abraunegg/onedrive/blob/master/docs/USAGE.md#configuration )
2019-01-22 02:31:57 +01:00
2020-07-03 21:34:42 +02:00
### 7. Sync multiple accounts
2019-11-20 21:02:56 +01:00
There are many ways to do this, the easiest is probably to
1. Create a second docker config volume (replace `Work` with your desired name): `docker volume create onedrive_conf_Work`
2. And start a second docker monitor container (again replace `Work` with your desired name):
```
2021-03-05 21:07:54 +01:00
export ONEDRIVE_DATA_DIR_WORK="/home/abraunegg/OneDriveWork"
mkdir -p ${ONEDRIVE_DATA_DIR_WORK}
2022-06-02 10:58:13 +02:00
docker run -it --restart unless-stopped --name onedrive_Work -v onedrive_conf_Work:/onedrive/conf -v "${ONEDRIVE_DATA_DIR_WORK}:/onedrive/data" driveone/onedrive:latest
2019-11-20 21:02:56 +01:00
```
2019-01-22 02:31:57 +01:00
## Run or update with one script
If you are experienced with docker and onedrive, you can use the following script:
2019-01-23 02:20:52 +01:00
2019-01-22 02:31:57 +01:00
```bash
2022-03-06 00:01:01 +01:00
# Update ONEDRIVE_DATA_DIR with correct OneDrive directory path
2021-03-05 21:07:54 +01:00
ONEDRIVE_DATA_DIR="${HOME}/OneDrive"
2022-03-06 00:01:01 +01:00
# Create directory if non-existant
mkdir -p ${ONEDRIVE_DATA_DIR}
2019-01-22 02:31:57 +01:00
firstRun='-d'
2022-06-02 10:58:13 +02:00
docker pull driveone/onedrive:latest
2022-03-06 00:01:01 +01:00
docker inspect onedrive_conf > /dev/null 2>& 1 || { docker volume create onedrive_conf; firstRun='-it'; }
docker inspect onedrive > /dev/null 2>& 1 & & docker rm -f onedrive
2022-06-02 10:58:13 +02:00
docker run $firstRun --restart unless-stopped --name onedrive -v onedrive_conf:/onedrive/conf -v "${ONEDRIVE_DATA_DIR}:/onedrive/data" driveone/onedrive:latest
2019-01-22 02:31:57 +01:00
```
2019-09-09 05:44:07 +02:00
## Environment Variables
| Variable | Purpose | Sample Value |
| ---------------- | --------------------------------------------------- |:-------------:|
| < B > ONEDRIVE_UID< / B > | UserID (UID) to run as | 1000 |
| < B > ONEDRIVE_GID< / B > | GroupID (GID) to run as | 1000 |
2019-09-23 22:13:28 +02:00
| < B > ONEDRIVE_VERBOSE< / B > | Controls "--verbose" switch on onedrive sync. Default is 0 | 1 |
| < B > ONEDRIVE_DEBUG< / B > | Controls "--verbose --verbose" switch on onedrive sync. Default is 0 | 1 |
2020-10-16 22:11:00 +02:00
| < B > ONEDRIVE_DEBUG_HTTPS< / B > | Controls "--debug-https" switch on onedrive sync. Default is 0 | 1 |
2019-09-23 22:13:28 +02:00
| < B > ONEDRIVE_RESYNC< / B > | Controls "--resync" switch on onedrive sync. Default is 0 | 1 |
2020-10-26 19:49:25 +01:00
| < B > ONEDRIVE_DOWNLOADONLY< / B > | Controls "--download-only" switch on onedrive sync. Default is 0 | 1 |
2020-12-20 21:06:18 +01:00
| < B > ONEDRIVE_LOGOUT< / B > | Controls "--logout" switch. Default is 0 | 1 |
2022-03-07 19:35:00 +01:00
| < B > ONEDRIVE_REAUTH< / B > | Controls "--reauth" switch. Default is 0 | 1 |
2021-11-22 21:08:04 +01:00
| < B > ONEDRIVE_AUTHFILES< / B > | Controls "--auth-files" option. Default is "" | "authUrl:responseUrl" |
| < B > ONEDRIVE_AUTHRESPONSE</ B > | Controls "--auth-response" option. Default is "" | See [here ](https://github.com/abraunegg/onedrive/blob/master/docs/USAGE.md#authorize-the-application-with-your-onedrive-account ) |
2019-09-23 22:13:28 +02:00
### Usage Examples
**Verbose Output:**
```bash
2022-06-02 10:58:13 +02:00
docker container run -e ONEDRIVE_VERBOSE=1 -v onedrive_conf:/onedrive/conf -v "${ONEDRIVE_DATA_DIR}:/onedrive/data" driveone/onedrive:latest
2019-09-23 22:13:28 +02:00
```
**Debug Output:**
```bash
2022-06-02 10:58:13 +02:00
docker container run -e ONEDRIVE_DEBUG=1 -v onedrive_conf:/onedrive/conf -v "${ONEDRIVE_DATA_DIR}:/onedrive/data" driveone/onedrive:latest
2019-09-23 22:13:28 +02:00
```
**Perform a --resync:**
```bash
2022-06-02 10:58:13 +02:00
docker container run -e ONEDRIVE_RESYNC=1 -v onedrive_conf:/onedrive/conf -v "${ONEDRIVE_DATA_DIR}:/onedrive/data" driveone/onedrive:latest
2019-09-23 22:13:28 +02:00
```
**Perform a --resync and --verbose:**
```bash
2022-06-02 10:58:13 +02:00
docker container run -e ONEDRIVE_RESYNC=1 -e ONEDRIVE_VERBOSE=1 -v onedrive_conf:/onedrive/conf -v "${ONEDRIVE_DATA_DIR}:/onedrive/data" driveone/onedrive:latest
2019-09-23 22:13:28 +02:00
```
2019-09-09 05:44:07 +02:00
2020-12-20 21:06:18 +01:00
**Perform a --logout and re-authenticate:**
```bash
2022-06-02 10:58:13 +02:00
docker container run -it -e ONEDRIVE_LOGOUT=1 -v onedrive_conf:/onedrive/conf -v "${ONEDRIVE_DATA_DIR}:/onedrive/data" driveone/onedrive:latest
2020-12-20 21:06:18 +01:00
```
2018-12-04 01:59:03 +01:00
## Build instructions
2020-06-28 00:48:01 +02:00
### Build Environment Requirements
* Build environment must have at least 1GB of memory & 2GB swap space
There are 2 ways to validate this requirement:
2021-03-14 02:59:17 +01:00
* Modify the file `/etc/dphys-swapfile` and edit the `CONF_SWAPSIZE` , for example: `CONF_SWAPSIZE=2048` . A reboot is required to make this change effective.
2020-06-28 00:48:01 +02:00
* Dynamically allocate a swapfile for building:
```bash
cd /var
sudo fallocate -l 1.5G swapfile
sudo chmod 600 swapfile
sudo mkswap swapfile
sudo swapon swapfile
# make swap permanent
sudo nano /etc/fstab
# add "/swapfile swap swap defaults 0 0" at the end of file
# check it has been assigned
swapon -s
free -h
```
2021-03-14 02:59:17 +01:00
### Building a custom Docker image
2021-01-08 20:13:09 +01:00
You can also build your own image instead of pulling the one from [hub.docker.com ](https://hub.docker.com/r/driveone/onedrive ):
2019-01-06 00:14:49 +01:00
```bash
2018-12-04 01:59:03 +01:00
git clone https://github.com/abraunegg/onedrive
2019-01-25 15:03:40 +01:00
cd onedrive
2019-06-11 10:40:05 +02:00
docker build . -t local-onedrive -f contrib/docker/Dockerfile
2018-12-04 01:59:03 +01:00
```
2019-02-16 20:13:19 +01:00
There are alternate, smaller images available by building
2022-03-07 09:25:34 +01:00
Dockerfile-debian or Dockerfile-alpine. These [multi-stage builder
2019-02-16 20:13:19 +01:00
pattern](https://docs.docker.com/develop/develop-images/multistage-build/)
Dockerfiles require Docker version at least 17.05.
2022-03-07 09:25:34 +01:00
#### How to build and run a custom Docker image based on Debian
2019-02-16 20:13:19 +01:00
``` bash
2022-03-07 09:25:34 +01:00
docker build . -t local-ondrive-debian -f contrib/docker/Dockerfile-debian
docker container run -v onedrive_conf:/onedrive/conf -v "${ONEDRIVE_DATA_DIR}:/onedrive/data" local-ondrive-debian:latest
2019-02-16 20:13:19 +01:00
```
2021-03-14 02:59:17 +01:00
#### How to build and run a custom Docker image based on Alpine Linux
2019-02-16 20:13:19 +01:00
``` bash
2019-06-11 10:40:05 +02:00
docker build . -t local-ondrive-alpine -f contrib/docker/Dockerfile-alpine
2021-03-14 02:59:17 +01:00
docker container run -v onedrive_conf:/onedrive/conf -v "${ONEDRIVE_DATA_DIR}:/onedrive/data" local-ondrive-alpine:latest
2019-02-16 20:13:19 +01:00
```
2021-01-08 20:13:09 +01:00
2021-03-14 02:59:17 +01:00
#### How to build and run a custom Docker image for ARMHF (Raspberry Pi)
Compatible with:
* Raspberry Pi
* Raspberry Pi 2
* Raspberry Pi Zero
* Raspberry Pi 3
* Raspberry Pi 4
2021-01-08 20:13:09 +01:00
``` bash
2022-05-28 00:38:57 +02:00
docker build . -t local-onedrive-armhf -f contrib/docker/Dockerfile-debian
docker container run -v onedrive_conf:/onedrive/conf -v "${ONEDRIVE_DATA_DIR}:/onedrive/data" local-onedrive-armhf:latest
2021-03-14 02:59:17 +01:00
```
#### How to build and run a custom Docker image for AARCH64 Platforms
``` bash
2022-03-07 09:25:34 +01:00
docker build . -t local-onedrive-aarch64 -f contrib/docker/Dockerfile-debian
2021-03-14 02:59:17 +01:00
docker container run -v onedrive_conf:/onedrive/conf -v "${ONEDRIVE_DATA_DIR}:/onedrive/data" local-onedrive-aarch64:latest
2021-01-08 20:13:09 +01:00
```