Dockerhub page: https://hub.docker.com/r/insrch/rsync
Initially, I was looking for a ready-made solution but couldn't find one that met my needs, especially with support for ARM and a simple setup. So, I decided to create my own Docker image and share it for others who are also looking for an easy-to-use solution.
By specifying the folder with the SSH key for remote connection, the sync schedule, the remote folder path, along with the host and user details, your files will be copied to the folder on the host where the container is running.
This Docker image provides a lightweight, automated solution for synchronizing remote files using rsync over SSH. It is designed for scheduled sync operations using cron, ensuring that remote directories stay up to date without manual intervention.
- Automated file synchronization using
rsync. - Secure SSH authentication via private keys.
- Customizable cron scheduling for periodic syncs.
PUID(User ID) andPGID(Group ID) set the file ownership for synchronized files. They ensure the files are written with the correct user and group permissions on the host system.- Lightweight Alpine-based image for minimal resource usage.
docker run -d \
--name rsync \
-v /path/to/local_folder:/data \
-v /path/to/ssh_keys:/mnt/ssh_keys:ro \
-e REMOTE_USER=user \
-e REMOTE_HOST=host.com \
-e REMOTE_PATH=/remote/directory \
-e SSH_KEY_FILE=id_rsa \
-e CRON_SCHEDULE="0 * * * *" \
-e PUID=1000 \
-e PGID=1000 \
-e TZ=Etc/UTC \
--restart unless-stopped \
insrch/rsync:latest| Variable | Description | Default |
|---|---|---|
REMOTE_USER |
Username for the remote server | Required |
REMOTE_HOST |
Remote server address | Required |
REMOTE_PATH |
Directory on the remote server to sync from | Required |
SSH_KEY_FILE |
SSH private key filename that sould be used for remote connection | id_rsa |
CRON_SCHEDULE |
Cron expression defining sync schedule | Required |
PUID |
User ID for file ownership during sync | 1000 |
PGID |
Group ID for file ownership during sync | 1000 |
TZ |
Timezone for the container (e.g., UTC, Europe/London) |
UTC |
docker run -d \
-v ~/Downloads:/data:/data \
-v ~/.ssh:/mnt/ssh_keys:ro \
-e REMOTE_USER=ubuntu \
-e REMOTE_HOST=192.168.69.12 \
-e REMOTE_PATH=/home/ubuntu/downloads \
-e SSH_KEY_FILE=id_rsa \
-e CRON_SCHEDULE="0 2 * * *" \
insrch/rsync:latestThis configuration syncs files from the remote directory every day at 2 AM.
services:
rsync:
image: insrch/rsync:latest
container_name: rsync
restart: unless-stopped
volumes:
- /local/data:/data
- /path/to/ssh_keys:/mnt/ssh_keys:ro
environment:
- REMOTE_USER=user
- REMOTE_HOST=example.com
- REMOTE_PATH=/remote/directory
- SSH_KEY_FILE=id_rsa
- CRON_SCHEDULE=0 3 * * *
- PUID=1000
- PGID=1000
- TZ=Etc/UTCThis example sets up a sync at 3 AM daily using Docker Compose.
When using volumes (-v flags), permissions issues can occur between the host OS and the container. To avoid this, you can specify the user PUID and group PGID.
Make sure that any volume directories on the host are owned by the same user and group you specify. This will resolve any permission issues seamlessly.
For example, if PUID=1000 and PGID=1000, you can find your own identifiers by running the following command:
id your_userExample output:
uid=1000(your_user) gid=1000(your_user) groups=1000(your_user)Ensure the SSH key is correctly mounted and the file exists:
ls -l /path/to/ssh_keys/If syncing fails due to permission errors, adjust ownership:
chown 1000:1000 /local/data -RUse the following command to inspect the logs:
docker logs -f container_idIf you would like to contribute, feel free to submit a pull request or open an issue on GitHub.