just like linuxserver/openssh-server with added rsync
324
This is one way syncing solution so we need source and destination implementation.
lsync,ssh-client,rsyncrsyncBooth images aditionaly contains packages net-tools, tree, vim for easer debuging during trouble shooting. Because services need to be high available.
See documentation of base image linuxserver/openssh-server.
Plus you can:
Instead of using enviroment properties PUBLIC_KEY and PUBLIC_KEY_FILE use rather AUTHORIZED_KEYS and AUTHORIZED_KEYS_FILE.
This properties correctly merge multiple keys (seppareted by new line) to authorized_keys.
Plus authorized_key can be updated without reboot by command:
docker exec $container merge-audthorized_keys
You can use ssh-entrypoint.sh as command for authorized keys which set default working directory to /data for all ssh connections (works also with lsync, scp, etc.).
Usage:
-e AUTHORIZED_KEYS='command="ssh-entrypoint.sh \"${SSH_ORIGINAL_COMMAND:-bash -l}\"" ssh-rsa AAAAXY...Z== comment'
Image uses lsyncd preconfiured by docker-entrypoint.sh.
Configuration consist of two steps:
~/.ssh/config like:
Host $TARGET_HOST
User $TARGET_USER
Port $TARGET_SSH_PORT
IdentityFile $SSH_KEY_FILE
CheckHostIP no
SSH_KEY is provided, its contnet is automaticaly strored to file and name of file in SSH_KEY_FILE~/.ssh/known_hosts is automaticlaly created using HOST_KEY or at startup.ssh hostname inside container.~/lsyncd.conf.lua like:
settings {
statusFile = "$HOME/lsyncd.status",
nodaemon = true,
insist = true,
inotifyMode = "${INOTIFY_MODE:-CloseWrite}",
}
sync {
default.rsyncssh,
source = "$SOURCE_PATH:-/var/source", -- source path inside container
host = "$TARGET_HOST",
targetdir = "$TARGET_PATH", -- path at remote ssh server
delay = ${SYNC_DELAY:-0},
excludeFrom = "$HOME/lsyncd.excludes", -- file automaticaly created from env EXCLUDES
delete = "${DELETE:-running}", -- IMPORTAT
rsync = {
archive = ${RSYNC_ARCHIVE:-true},
compress = ${RSYNC_COMPRESS:-false},
}
}
sync.delete must by set to running (or false) if multiple sources are synchronized to same target.sync.delay allow pospond synchronization n seconds, which optimize synchronization process by invoking rsync less frequent.| Property | Type | Default Value | Description |
|---|---|---|---|
| INOTIFY_MODE | enum | CloseWrite | "Modify", "CloseWrite" or "CloseWrite or Modify" |
| SOURCE_PATH | dir | /var/source | where source direcory is mounted, can be read-only |
| SYNC_DELAY | number | 0 | seconds |
| EXCLUDES | pattern | *~ | rsync patterns separated by newline |
| DELETE | enum | running | true, false, startup or running |
| RSYNC_ARCHIVE | boolean | true | |
| RSYNC_COMPRESS | boolean | true | |
| TARGET_USER | string | required | |
| TARGET_HOST | hostname | required | |
| TARGET_SSH_PORT | number | 22 | |
| TARGET_PATH | path | required | |
| SSH_KEY | string | required if not SSH_KEY_FILE (SSH_KEY has precedence) | |
| SSH_KEY_FILE | path | required if not SSH_KEY, identity file mounted to container | |
| HOST_KEY | string | optional, ecdsa-sha2 public key of remote host (used in known_hosts) |
install-lsyncdThis script allows easy to setup client service running from docker.
Just go to dicrectory wich sould be synchronized and launch command:
install-lsyncd user@host:port:/target/dir -i /path/to/id_rsa --delay=2
LASTEST="$(curl -sI https://github.com/solargis/docker-lsyncd/releases/latest | perl -ne '/^Location: .*\/releases\/tag\/(\S+)/i && print $1')";
sudo curl -Ls https://github.com/solargis/docker-lsyncd/releases/download/$LASTEST/install-lsyncd -o /usr/local/bin/install-lsyncd && sudo chmod +x /usr/local/bin/install-lsyncd
For testing use ./demo.sh which prepares environment and start docker-compose.
Containners in docker-compose.yml works according to this schema:
Usage:
./demo.sh setup - prepare envinoment source and target directories, client and host keys, .env file./demo.sh start - call ./demo.sh setup and then start containers by docker-compose up./demo.sh watch - call ./demo.sh start and then start watching source and target directories./demo.sh stop - destory containers by docker-compose down./demo.sh cleanup - call ./demo.sh stop and then remove keys, source and target directoriesNote:
Sometimes, after fresh creation of bind directories, the changes are not reflected inside conainer .
If synchronization not works, you can quickly chcek if local files match containers files by executing: ./demo.sh check.
If not, then you simply creacreate containers by ./demo.sh stop && ./demo.sh stop.
Content type
Image
Digest
Size
21.6 MB
Last updated
over 5 years ago
docker pull solargis/openssh-server