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

  • Firefox 122 als .deb Paket

    Linux
    1
    0 Stimmen
    1 Beiträge
    103 Aufrufe
    Niemand hat geantwortet
  • PHP Webseite lokal einhängen mit sshfs

    PHP
    1
    0 Stimmen
    1 Beiträge
    40 Aufrufe
    Niemand hat geantwortet
  • NAS 2023 - Software Teil 2

    Angeheftet Verschoben Linux
    1
    0 Stimmen
    1 Beiträge
    158 Aufrufe
    Niemand hat geantwortet
  • Docker - Portainer

    Linux
    3
    0 Stimmen
    3 Beiträge
    608 Aufrufe
    FrankMF

    Dann grabe ich das mal wieder aus 😉

    Bedingt durch den Wegfall meines Proxmox, musste ich mir Gedanken darüber machen, wie ein paar Dienste auch weiterhin laufen sollen. Um mal die zwei wichtigsten zu nennen.

    checkmk DokuWiki

    Diese sollen später, wenn der zweite NanoPi R5S aus China da ist, dort laufen. Da der aber mit der Schneckenpost kommt, kann man ja in der Zwischenzeit mal wieder mit Docker spielen.

    Ich erinnerte mich daran, das checkmk eine sehr gute Anleitung hat, so das ich das mal wieder ausprobierte. Klappte einwandfrei. Dann erinnerte mich an Portainer und dachte mir, das probiere ich mal wieder aus 🙂

    1d2dc9b3-ad71-45c5-b552-72c88a1bf773-grafik.png

    Ich hatte übrigens die Endpoints gesucht und nicht gefunden, die heißen jetzt Environments. Auf dem Bild ist noch keiner eingerichtet.

    4bdbf196-1b36-4e65-94d0-0e56daa473bf-grafik.png

    Irgendwie ist das wirklich richtig gute Software. Ich mag den Portainer und auch als selbst ausgebildeter ITler 😉 kommt man damit sehr schnell ganz gut zurecht.

    Ja, man kann die ganzen Docker Befehle auch über die Konsole eingeben, was ich normalerweise auch mit ganz vielen Dingen mache, aber das macht hier einfach Spaß. Man hat auch schnell einen guten Überblick was wo läuft usw.

    Wer so was sucht, einfach mal ausprobieren. Klare Empfehlung von mir.

  • Mobian - vollverschlüsselt

    Software
    1
    0 Stimmen
    1 Beiträge
    237 Aufrufe
    Niemand hat geantwortet
  • Redis Replication

    Angeheftet Verschoben Redis
    4
    1 Stimmen
    4 Beiträge
    427 Aufrufe
    FrankMF

    Um die Verbindung zu testen, kann man folgende Befehle nutzen.

    redis-cli -h 10.1.1.0 -p 6379 -a <PASSWORD>

    und

    telnet 10.1.1.0 6379
  • NAS - Cups & Sane

    Linux
    1
    0 Stimmen
    1 Beiträge
    469 Aufrufe
    Niemand hat geantwortet
  • NodeBB - Upgrade auf v1.9.0

    NodeBB
    2
    0 Stimmen
    2 Beiträge
    797 Aufrufe
    FrankMF

    Da oben fehlt ein Schritt.

    cd nodebb (or path to where nodebb is installed) ./nodebb stop git fetch git checkout v1.12.x git merge origin/v1.12.x ./nodebb upgrade

    Beim nächsten Upgrade testen.