From fa55cd9d87270aba991ff42badd4afe70e126395 Mon Sep 17 00:00:00 2001 From: Andreas Meier Date: Tue, 29 Oct 2024 12:59:40 +0100 Subject: [PATCH] first commit --- Dockerfile | 14 ++++++++ README.md | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++ run.sh | 29 ++++++++++++++++ 3 files changed, 143 insertions(+) create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 run.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2cfb698 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM ubuntu:latest +MAINTAINER dresi + +RUN apt-get update && \ + DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends rsync && \ + apt-get clean autoclean && \ + apt-get autoremove -y && \ + rm -rf /var/lib/{apt,dpkg,cache,log}/ + +EXPOSE 873 +VOLUME /volume +ADD ./run.sh /usr/local/bin/run.sh +RUN chmod +x /usr/local/bin/run.sh +ENTRYPOINT ["/usr/local/bin/run.sh"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..afd4d5e --- /dev/null +++ b/README.md @@ -0,0 +1,100 @@ +rsync +===== + +Simple rsync server running in a docker container + +This is inspired by https://github.com/nabeken/docker-volume-container-rsync and https://github.com/bfosberry/rsync + +## Basic usage + +Launch the container via docker: +``` +docker run -d -p :873 --name rsyncd thomfab/docker-rsyncd +``` + +You can connect to the rsync server you just created with: + +``` +rsync rsync://:/ +volume volume +``` + +To sync: + +``` +rsync -avP /path/to/dir rsync://:/volume/ +``` + +## Advanced + +Some variables can be customized : + +### VOLUME +To set the name of the sync volume. Default is "volume" + +Example : +``` +docker run -d -p :873 --name rsyncd \ + -e VOLUME="backup" \ + thomfab/docker-rsyncd +``` +which will give : +``` +rsync rsync://:/ +backup backup +``` + +### ALLOW +By default, rsync server accepts a connection only from `192.168.0.0/16` and `172.12.0.0/12` for security reasons. +You can override via an environment variable like this: + +``` +docker run -d -p :873 \ + --name rsyncd \ + -e ALLOW='10.0.0.0/8 x.x.x.x/y' \ + thomfab/docker-rsyncd +``` + +### OWNER +By default the user "nobody" is used. You can customize and pass the id of a user the docker host (so that file perms are correct). +Example, if your docker host has a user "ubuntu" with id 1000 you can use : +``` +docker run -d -p :873 \ + --name rsyncd \ + -e OWNER=1000 \ + thomfab/docker-rsyncd +``` +Files created in the volume by rsyncd will belong to the user ubuntu (see volumes below). + +### GROUP +By default the group "nogroup" is used. You can also customize and pass the id of a group on the docker host. +Example, if your docker host has a group "users" with id 100 you can use : +``` +docker run -d -p :873 \ + --name rsyncd \ + -e GROUP=100 \ + thomfab/docker-rsyncd +``` +Files created in the volume by rsyncd will belong to the group users. + +### Sync volume +The sync folder exposed by rsyncd is a docker volume. You can map it to a local folder on the docker host : +Example, if your docker host has a user "ubuntu" with id 1000 you can use : +``` +docker run -d -p :873 \ + --name rsyncd \ + -v /path/to/host/folder:/volume \ + thomfab/docker-rsyncd +``` + +### Full example +``` +docker run -d -p 873:873 \ + --name rsyncd \ + -e VOLUME="backup" \ + -e OWNER=1000 \ + -e GROUP=100 \ + -v /srv/backup:/volume \ + thomfab/docker-rsyncd +``` +This will start an rsync daemon, exposed on the standard port, with a volume named "backup", and map it to the host folder /srv/backup. Files created during sync will belong to user "ubuntu" and group "users" on a standard Ubuntu install. diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..4467fb1 --- /dev/null +++ b/run.sh @@ -0,0 +1,29 @@ +#!/bin/bash +VOLUME=${VOLUME:-"volume"} +ALLOW=${ALLOW:-192.168.0.0/16 172.16.0.0/12} +OWNER=${OWNER:-nobody} +GROUP=${GROUP:-nogroup} + +# create users matching ids passed if necessary +if [ "${GROUP}" != "nogroup" ]; then + groupadd -g ${GROUP} rsyncdgroup +fi +if [ "${OWNER}" != "nobody" ]; then + groupadd -u ${OWNER} -G rsyncdgroup rsyncduser +fi + +[ -f /etc/rsyncd.conf ] || cat < /etc/rsyncd.conf +uid = ${OWNER} +gid = ${GROUP} +use chroot = yes +pid file = /var/run/rsyncd.pid +log file = /dev/stdout +[${VOLUME}] + hosts deny = * + hosts allow = ${ALLOW} + read only = false + path = /volume + comment = ${VOLUME} +EOF + +exec /usr/bin/rsync --no-detach --daemon --config /etc/rsyncd.conf "$@"