Docker Community Forums

Share and learn in the Docker community.

Question: Best practices to routinely populate data for a container from a remote server?


(Haertig) #1

I have a question on best practices for populating data for a docker container from a remote server. Thanks in advance for any help/tips/recommendations on the “best practice” way to accomplish this.

This is what I currently have (and it works fine as-is, but I’m looking for “best practices”):

On the docker host server (outside of docker), I’m using a systemd timer to fire off a daily job that rsyncs content from a different server onto the docker server. This directory of data is bind mounted into a docker container. The systemd host job does the rsync and then restarts the docker container, because the container does not automatically pick up the changes from the rsync. I don’t know if this is an issue with docker, or an issue for the app running in the docker container (calibre-web). But restarting the container gives the app access to anything new that comes across from the rsync.

I am wondering if there is a better way to accomplish the task above. Maybe another container that does the rsync into a docker volume that is shared with the container that runs the app (replacing the bind mount with a docker volume)? That then begs the question of “How do I set up a container to routinely run an rsync job to a remote server?” Do I set up cron/systemd inside the rsync container, or do I do that outside, at the docker host level?

If anyone cares, here is my current setup (forgive any newbie mistakes - I’m just learning docker and systemd - what I have works, but may not be optimal):

/var/opt/docker/docker-compose.yml

version: '3'

networks:

  frontend:
    driver: bridge

services:

  www:
    image: linuxserver/letsencrypt
    container_name: letsencrypt
    ports:
      - 80:80
      - 443:443
    volumes:
      - /var/opt/docker/letsencrypt/config:/config
    environment:
      - EMAIL=blahblahblah@blah.com
      - URL=blahblahblah.blah.net
      - VALIDATION=http
      - TZ=America/Denver
      - PUID=65534
      - PGID=65534
    networks:
      - frontend
    depends_on:
      - books
    restart: always

  books:
    image: linuxserver/calibre-web
    container_name: calibre-web
    volumes:
      - /var/opt/docker/calibre-web/config:/config
      - /var/opt/calibre:/books
    environment:
      - PUID=1002
      - PGID=1001
    networks:
      - frontend
    restart: unless-stopped

Note: linuxserver/letsencrypt uses NGINX as a reverse proxy and authentication for the calibre-web container.

One the docker host, outside of docker, /usr/local/sbin/rsync_calibre_books.sh:

#!/bin/bash

/usr/bin/rsync -avzh --password-file=/root/credentials/rsync.calibre.credentials --chown=calibre:calibre rsync://calibre@10.192.0.2:873/files/ /var/opt/calibre/

/bin/sleep 2

/usr/bin/docker container restart calibre-web

One the docker host, outside of docker, /etc/systemd/system/rsync_calibre.service:

[Unit]
Description=Rsync Calibre books from 10.192.0.2 to /var/opt/calibre/

[Service]
Type=simple
ExecStart=/usr/local/sbin/rsync_calibre_books.sh

[Install]
WantedBy=default.target

One the docker host, outside of docker, /etc/systemd/system/rsync_calibre.timer:

[Unit]
Description=Timer to Rsync Calibre books from 10.192.0.2
RefuseManualStart=no
RefuseManualStop=no

[Timer]
Persistent=true
OnBootSec=120
OnCalendar=*-*-* 03:00:00
Unit=rsync_calibre.service

[Install]
WantedBy=timers.target