Share files generated by Docker with Synology CloudSync

Just what is going on here

Share files generated by Docker with Synology CloudSync

posted in docker on  •   • 

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!?

Synology Configuration

Enable NFS

Steps: Control Panel > File Services > NFS > Enable

Enabling NFS v4 on Synology

Enable NFS on Shared Drive

  • Control Panel > Shared Folder > right Click “workspace” > Edit > NFS Permissions
    • Create > Hostname or IP: 127.0.0.1 > Save

Enabling NFS on Synology Shared Folder

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

Minimal CRON job setup

  • 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!


Stuff that came into being during the making of this post
Other interesting reads
Tags: synology