Skip to content

Docker & Redis Datenbank

Verschoben Linux
  • Ich habe es endlich geschafft, meinen Redis Container so zu starten, das er meine Konfigurationsdatei nutzt und die Daten permanent gespeichert werden. Das hier ist der erfolgreiche Aufruf.

    docker run --name redis -v /local-data/:/data -v /root/redis.conf:/redis-stack.conf -d redis/redis-stack-server:latest
    

    Ok, Docker hat einen ganzen Haufen Parameter zum Einstellen, hier ein Beispiel, nur für docker run

    [frank-ms7c92 ~]# docker run --help
    
    Usage:  docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
    
    Create and run a new container from an image
    
    Aliases:
      docker container run, docker run
    
    Options:
          --add-host list                  Add a custom host-to-IP mapping (host:ip)
      -a, --attach list                    Attach to STDIN, STDOUT or STDERR
          --blkio-weight uint16            Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)
          --blkio-weight-device list       Block IO weight (relative device weight) (default [])
          --cap-add list                   Add Linux capabilities
          --cap-drop list                  Drop Linux capabilities
          --cgroup-parent string           Optional parent cgroup for the container
          --cgroupns string                Cgroup namespace to use (host|private)
                                           'host':    Run the container in the Docker host's cgroup namespace
                                           'private': Run the container in its own private cgroup namespace
                                           '':        Use the cgroup namespace as configured by the
                                                      default-cgroupns-mode option on the daemon (default)
          --cidfile string                 Write the container ID to the file
          --cpu-period int                 Limit CPU CFS (Completely Fair Scheduler) period
          --cpu-quota int                  Limit CPU CFS (Completely Fair Scheduler) quota
          --cpu-rt-period int              Limit CPU real-time period in microseconds
          --cpu-rt-runtime int             Limit CPU real-time runtime in microseconds
      -c, --cpu-shares int                 CPU shares (relative weight)
          --cpus decimal                   Number of CPUs
          --cpuset-cpus string             CPUs in which to allow execution (0-3, 0,1)
          --cpuset-mems string             MEMs in which to allow execution (0-3, 0,1)
      -d, --detach                         Run container in background and print container ID
          --detach-keys string             Override the key sequence for detaching a container
          --device list                    Add a host device to the container
          --device-cgroup-rule list        Add a rule to the cgroup allowed devices list
          --device-read-bps list           Limit read rate (bytes per second) from a device (default [])
          --device-read-iops list          Limit read rate (IO per second) from a device (default [])
          --device-write-bps list          Limit write rate (bytes per second) to a device (default [])
          --device-write-iops list         Limit write rate (IO per second) to a device (default [])
          --disable-content-trust          Skip image verification (default true)
          --dns list                       Set custom DNS servers
          --dns-option list                Set DNS options
          --dns-search list                Set custom DNS search domains
          --domainname string              Container NIS domain name
          --entrypoint string              Overwrite the default ENTRYPOINT of the image
      -e, --env list                       Set environment variables
          --env-file list                  Read in a file of environment variables
          --expose list                    Expose a port or a range of ports
          --gpus gpu-request               GPU devices to add to the container ('all' to pass all GPUs)
          --group-add list                 Add additional groups to join
          --health-cmd string              Command to run to check health
          --health-interval duration       Time between running the check (ms|s|m|h) (default 0s)
          --health-retries int             Consecutive failures needed to report unhealthy
          --health-start-period duration   Start period for the container to initialize before starting health-retries countdown (ms|s|m|h) (default 0s)
          --health-timeout duration        Maximum time to allow one check to run (ms|s|m|h) (default 0s)
          --help                           Print usage
      -h, --hostname string                Container host name
          --init                           Run an init inside the container that forwards signals and reaps processes
      -i, --interactive                    Keep STDIN open even if not attached
          --ip string                      IPv4 address (e.g., 172.30.100.104)
          --ip6 string                     IPv6 address (e.g., 2001:db8::33)
          --ipc string                     IPC mode to use
          --isolation string               Container isolation technology
          --kernel-memory bytes            Kernel memory limit
      -l, --label list                     Set meta data on a container
          --label-file list                Read in a line delimited file of labels
          --link list                      Add link to another container
          --link-local-ip list             Container IPv4/IPv6 link-local addresses
          --log-driver string              Logging driver for the container
          --log-opt list                   Log driver options
          --mac-address string             Container MAC address (e.g., 92:d0:c6:0a:29:33)
      -m, --memory bytes                   Memory limit
          --memory-reservation bytes       Memory soft limit
          --memory-swap bytes              Swap limit equal to memory plus swap: '-1' to enable unlimited swap
          --memory-swappiness int          Tune container memory swappiness (0 to 100) (default -1)
          --mount mount                    Attach a filesystem mount to the container
          --name string                    Assign a name to the container
          --network network                Connect a container to a network
          --network-alias list             Add network-scoped alias for the container
          --no-healthcheck                 Disable any container-specified HEALTHCHECK
          --oom-kill-disable               Disable OOM Killer
          --oom-score-adj int              Tune host's OOM preferences (-1000 to 1000)
          --pid string                     PID namespace to use
          --pids-limit int                 Tune container pids limit (set -1 for unlimited)
          --platform string                Set platform if server is multi-platform capable
          --privileged                     Give extended privileges to this container
      -p, --publish list                   Publish a container's port(s) to the host
      -P, --publish-all                    Publish all exposed ports to random ports
          --pull string                    Pull image before running ("always", "missing", "never") (default "missing")
      -q, --quiet                          Suppress the pull output
          --read-only                      Mount the container's root filesystem as read only
          --restart string                 Restart policy to apply when a container exits (default "no")
          --rm                             Automatically remove the container when it exits
          --runtime string                 Runtime to use for this container
          --security-opt list              Security Options
          --shm-size bytes                 Size of /dev/shm
          --sig-proxy                      Proxy received signals to the process (default true)
          --stop-signal string             Signal to stop the container
          --stop-timeout int               Timeout (in seconds) to stop a container
          --storage-opt list               Storage driver options for the container
          --sysctl map                     Sysctl options (default map[])
          --tmpfs list                     Mount a tmpfs directory
      -t, --tty                            Allocate a pseudo-TTY
          --ulimit ulimit                  Ulimit options (default [])
      -u, --user string                    Username or UID (format: <name|uid>[:<group|gid>])
          --userns string                  User namespace to use
          --uts string                     UTS namespace to use
      -v, --volume list                    Bind mount a volume
          --volume-driver string           Optional volume driver for the container
          --volumes-from list              Mount volumes from the specified container(s)
      -w, --workdir string                 Working directory inside the container
    

    Wir zerlegen das mal und schauen uns das Stück für Stück an. So das ich es hoffentlich dann verstehe und es auch für andere Container benutzen kann.

    docker run # Create and run a new container from an image
    

    Das ist einfach und gut zu verstehen 🙂

    --name redis # Assign a name to the container
    

    Auch nicht wirklich schwer.

    -v /local-data/:/data # Bind mount a volume
    

    Jetzt wird es endlich mal komplexer. Wir mounten einen lokalen Ordner /local-data/ Die schlanke Anleitung dazu, direkt von Docker.

    -v or --volume: Consists of three fields, separated by colon characters (:). The fields must be in the correct order, and the meaning of each field is not immediately obvious.

    In the case of named volumes, the first field is the name of the volume, and is unique on a given host machine. For anonymous volumes, the first field is omitted.

    The second field is the path where the file or directory are mounted in the container.

    The third field is optional, and is a comma-separated list of options, such as ro. These options are discussed below.

    Der Doppelpunkt dient als Trennzeichen. Und /data ist der Ordner im Docker Container. Als Zusammenfassung.

    1. /local-data/ # Lokaler Ordner auf dem Host
    2. Doppelpunkt als Trennzeichen
    3. /data # Ordner innerhalb des Docker Containers

    /local-data

    [frank-ms7c92 local-data]# ls -lha
    insgesamt 4,0K
    drwxr-xr-x 1 root root  16  7. Mär 19:10 .
    drwxr-xr-x 1 root root 272  7. Mär 19:01 ..
    -rw-r--r-- 1 root root 944  7. Mär 19:10 dump.rdb
    

    /data

    root@503c1b403529:/data# ls -lha
    total 4.0K
    drwxr-xr-x 1 root root  16 Mar  7 18:10 .
    drwxr-xr-x 1 root root 240 Mar  7 18:01 ..
    -rw-r--r-- 1 root root 944 Mar  7 18:10 dump.rdb
    

    Was mir aktuell noch unklar ist, wo wird Redis mitgeteil, die Daten in /data abzulegen? In meiner Konfiguration ist das nicht gesetzt? Ok schauen wir mal weiter, vielleicht wird es noch heller..

    -v /root/redis.conf:/redis-stack.conf  # Bind mount a volume
    

    Das jetzt in Kurzform, meine Konfiguration liegt auf dem Host im Rootverzeichnis und soll in den Container.

    1. /root/redis.conf # Konfiguration, liegt auf dem Host
    2. Doppelpunkt als Trennzeichen
    3. redis-stack.conf # Die Datei im Container

    Eben meine aktuelle Testkonfiguration

    bind 0.0.0.0
    port 6379
    databases 16
    pidfile /var/run/redis/redis-server.pid
    save 60 1
    #save 900 1
    save 300 10
    save 60 10000
    stop-writes-on-bgsave-error yes
    rdbcompression yes
    rdbchecksum yes
    dbfilename dump.rdb
    dir /
    

    Ich vermute, das die Angabe des Arbeitsverzeichnisses ( dir / ) dazu führt, das die redis-stack.conf im Rootverzeichnis auftaucht. Mir ist aktuell unklar, warum Redis die jetzt benutzt? Macht das Docker selbstständig?

    Ich weiß das sie auf alle Fälle geladen und auch benutzt wird. Habe ich über das Einstellen des Ports ausprobiert.

    Ok, hier kurz die Frage, warum taucht das dump.rdb im /data Verzeichnis auf? Macht das Docker von alleine?

    Ihe seht, ich habe hier leider immer noch viel Fragezeichen....

    -d # Run container in background and print container ID
    

    Das ist wieder etwas einfacher. Das startet den Docker Container als Daemon im Hintergrund. Kann man einfach mal ausprobieren und das -d weglassen, dann seht ihr was ich meine 😉

     redis/redis-stack-server:latest # Image
    

    Das ist das Image, was zum Bau des Docker Containers benutzt wird.

  • @FrankM sagte in Docker & Redis Datenbank:

    save 60 1
    #save 900 1
    save 300 10
    save 60 10000

    Hier kann man auch noch schön sehen, wie ich gekämpft habe, bis ich mal eine dump.rdb gesehen habe. Auch irgendwie logisch, das ich nie eine gesehen hatte, wenn man weiß das

    save 900 1
    

    bedeutet, das er alle 900 Sekunden speichert, wenn mindestens eine Änderung vorhanden ist. Das kann dann schon was dauern. Ich habe das dann mal verkürzt, damit ich schneller ein Ergebnis habe.

    save 60 1
    

    Das brachte mich dann dem Ziel näher. Danach konnte ich die dump.rdb auch finden.

    Bitte keine Redis DB ohne Passwort laufen lassen!

  • FrankMF FrankM verschob dieses Thema von Privat am

  • Fragen, Probleme, geht nicht?

    Angeheftet Support
    1
    0 Stimmen
    1 Beiträge
    64 Aufrufe
    Niemand hat geantwortet
  • 0 Stimmen
    2 Beiträge
    351 Aufrufe
    FrankMF

    Ok, ich war leider nicht in der Lage den CODE-Server hinter einem Proxy zu installieren. Das CODE-Team scheint Docker zu lieben und das andere nur am Rande zu machen. Ohne Liebe 🙂

    Da ich extrem lange Ladezeiten hatte und die Software insgesamt nicht den Eindruck machte, das man das gerne produktiv auf einem Server nutzen möchte, habe ich den Server eben wieder gelöscht.

    Jetzt fehlt mir leider, die deepl.com Anbindung, aber das kann man ja auch über die Webseite nutzen.

    Ich nutze jetzt wieder den eingebauten CODE-Server, der eigentlich ein App-Image ist.

    28c41010-5ce1-4f7c-89d5-1c9b253011d0-grafik.png

    Der klare Vorteil, es läuft incl. Dokumenten Freigabe 🙂

    Nicht vergessen, unter Allow list for WOPI requests kommen die Server Adressen des Nextcloud-Webservers rein!

    c1a06c2c-86b5-4750-a062-7ba9d8dd8253-grafik.png

  • 0 Stimmen
    2 Beiträge
    123 Aufrufe
    FrankMF

    Verkauft!

  • 0 Stimmen
    4 Beiträge
    276 Aufrufe
    FrankMF

    Es geht weiter, der erste ☕ und ich bin mit der Lösung nicht so richtig zufrieden, also suchen.

    Als erstes habe ich heute Morgen ein frisches SD-Karten Image mit Docker von FreindlyWrt genommen und auf meinem Test NanoPi R5S installiert. Dort mal die Config angeschaut um zu sehen, ob der Eintrag standardmäßig gesetzt ist. Doch dort taucht dann einmal eine ganz ander Config auf 🙄

    # The following settings require a restart of docker to take full effect, A reload will only have partial or no effect: # bip # blocked_interfaces # extra_iptables_args # device config globals 'globals' # option alt_config_file '/etc/docker/daemon.json' option enable '1' option data_root '/mnt/nvme_part2/docker' option log_level 'warn' option iptables '1' #list hosts 'unix:///var/run/docker.sock' # option bip '172.18.0.1/24' # option fixed_cidr '172.17.0.0/16' # option fixed_cidr_v6 'fc00:1::/80' # option ipv6 '1' # option ip '::ffff:0.0.0.0' # list dns '172.17.0.1' # list registry_mirrors 'https://<my-docker-mirror-host>' list registry_mirrors 'https://hub.docker.com' option remote_endpoint '0' # option bridge 'br-container' # Docker ignores fw3 rules and by default all external source IPs are allowed to connect to the Docker host. # See https://docs.docker.com/network/iptables/ for more details. # firewall config changes are only additive i.e firewall will need to be restarted first to clear old changes, # then docker restarted to load in new changes. config firewall 'firewall' option device 'docker0' list blocked_interfaces 'wan' option extra_iptables_args '--match conntrack ! --ctstate RELATED,ESTABLISHED' # allow outbound connections

    Das interessiert uns jetzt

    list blocked_interfaces 'wan' option extra_iptables_args '--match conntrack ! --ctstate RELATED,ESTABLISHED' # allow outbound connections

    Wenn ich das jetzt alles richtig verstehe, muss WAN geblockt sein, weil sonst der Docker Host offen im Netz steht (Hierbei bin ich mir nicht 100% sicher)
    Die zweite Zeile ist eine iptables Regel, die es den Containern dann ermöglicht das Internet zu erreichen.

    Das habe ich jetzt so eingestellt und getestet.

    root@b9ffae24913a:/# ping 1.1.1.1 PING 1.1.1.1 (1.1.1.1): 56 data bytes 64 bytes from 1.1.1.1: icmp_seq=0 ttl=57 time=17.151 ms 64 bytes from 1.1.1.1: icmp_seq=1 ttl=57 time=16.553 ms 64 bytes from 1.1.1.1: icmp_seq=2 ttl=57 time=20.630 ms 64 bytes from 1.1.1.1: icmp_seq=3 ttl=57 time=13.948 ms ^C--- 1.1.1.1 ping statistics --- 4 packets transmitted, 4 packets received, 0% packet loss round-trip min/avg/max/stddev = 13.948/17.071/20.630/2.382 ms root@b9ffae24913a:/# ping google.de PING google.de (142.250.185.195): 56 data bytes 64 bytes from 142.250.185.195: icmp_seq=0 ttl=58 time=23.797 ms 64 bytes from 142.250.185.195: icmp_seq=1 ttl=58 time=16.953 ms 64 bytes from 142.250.185.195: icmp_seq=2 ttl=58 time=19.441 ms ^C--- google.de ping statistics --- 3 packets transmitted, 3 packets received, 0% packet loss round-trip min/avg/max/stddev = 16.953/20.064/23.797/2.829 ms

    Ich hoffe mal das ich diese Thema jetzt zu den Akten legen kann.

    Wenn was falsch ist, bitte hier kommentieren, damit ich das ändern kann.

  • Nextcloud 23.0.3

    Nextcloud
    1
    0 Stimmen
    1 Beiträge
    123 Aufrufe
    Niemand hat geantwortet
  • Wenn dir der Redis-Server flöten geht....

    Verschoben Redis
    3
    0 Stimmen
    3 Beiträge
    519 Aufrufe
    FrankMF

    So, nach einer kleinen Pause und ein wenig nachdenken ist mir doch noch was eingefallen 😉

    Backports! Man so einfach!

    nano /etc/apt/sources.list

    Das folgende eintragen.

    # backports deb http://deb.debian.org/debian stretch-backports main

    Danach ein

    apt update

    Und dann schauen wir uns mal die Version an....

    apt -t stretch-backports search redis-server Sorting... Done Full Text Search... Done golang-github-stvp-tempredis-dev/stretch-backports 0.0~git20160122.0.83f7aae-1~bpo9+1 all Go package to start and stop temporary redis-server processes libtest-redisserver-perl/oldstable,oldstable 0.20-1 all redis-server runner for tests python-hiredis/oldstable,oldstable 0.2.0-1+b2 amd64 redis protocol reader for Python 2.X using hiredis python3-hiredis/oldstable,oldstable 0.2.0-1+b2 amd64 redis protocol reader for Python using hiredis redis/stretch-backports 5:5.0.3-3~bpo9+2 all Persistent key-value database with network interface (metapackage) redis-server/stretch-backports 5:5.0.3-3~bpo9+2 amd64 [residual-config] Persistent key-value database with network interface

    Und die habe ich gestern Abend gebaut.

    127.0.0.1:6379> INFO # Server redis_version:5.0.5

    Ok, das schmerzt jetzt 😛

  • Redis installieren

    Angeheftet Verschoben Redis
    1
    0 Stimmen
    1 Beiträge
    353 Aufrufe
    Niemand hat geantwortet
  • Redis Datenbank sichern

    Verschoben Redis
    1
    0 Stimmen
    1 Beiträge
    746 Aufrufe
    Niemand hat geantwortet