Share files generated by Docker with Synology CloudSync
posted in docker on • by Wouter Van Schandevijl •We needed to generate some files and share them with a third party. They preferred we put the files on our SharePoint since they already had access to it.
So we made a docker-compose
that scheduled a CRON
job to create the files in the shared folder.
The files were getting generated alright and other files were getting synced alright, but the generated files were not!?
In CloudSync Folder
Synology Configuration
Enable NFS
Steps: Control Panel > File Services > NFS > Enable
Enable NFS on Shared Drive
- Control Panel > Shared Folder > right Click “workspace” > Edit > NFS Permissions
- Create > Hostname or IP: 127.0.0.1 > Save
The Code
compose.yaml
Requires an .env
file with with: SYNC_DIR=/volume1/CloudSyncedFolder/shared-with-3rd-party
version: "3"
services:
cron_job:
# Sets up the CRON job
build: .
# Scheduled job write to /export
volumes:
- exportVolume:/export
volumes:
# The required magic
exportVolume:
driver: local
driver_opts:
type: nfs
o: nfsvers=4,addr=127.0.0.1,rw
# The folder the job writes to
# Shared with the 3rd party
device: ":${SYNC_DIR}"
Other files
- Dockerfile: Copies
sh
files to the container and runs start.sh - start.sh: Calls
crontab
to run create-file.sh and starts the deamon - create-file.sh:
touch /export/export.csv
NFWhat?
NFS or Network File System, a distributed file system protocol which allows you to access files over a network as if they were on the local disk. It has been around since 1984 and is pretty much the standard on Linux systems.
Thanks to NFS we get proper inotify
events and CloudSync picks up our files.
Crisis averted!
Outside CloudSync Folder
It might not be possible to create the files directly into the folder that CloudSync is active on.
The easy solution would be to create a symbolic link to the CloudSync folder; but, of course, that doesn’t work.
ln -s /volume1/Projects/GeneratedFiles /volume1/Dropbox/GeneratedProjectFiles
Scheduled rsync Task
An easy solution here is creating a recurring task to run rsync
.
- Synology DSM
- Control Panel > Services > Task Scheduler
- Create > Scheduled Task > User-defined script
- General: Set a task name
- Schedule: I kept the default of a daily sync
- Task Settings > Run command
rsync -av --delete /volume1/Projects/GeneratedFiles /volume1/Dropbox
This will create a folder GeneratedFiles
in /volume1/Dropbox
.
rsync options:
-a
: Archive mode to preserve file attributes (permissions, timestamps etc)-v
: Verbose output. You’ll have to select a folder for the output in Task Scheduler > Settings to actually see the output.--delete
: If your Docker container also deletes files--chown=CloudSync:CloudSync
: I didn’t have to change ownership for CloudSync to pick up the files
Of course you could also just add this to the docker-compose
😀