Redis Docker container

Easy Docker set-up using pre-built image:

(Ubuntu host in this example, but others should be similar)

# see

Docker run command:

docker run -d -v $(pwd)/redis.conf:/usr/local/etc/redis/redis.conf \
 -v /data/redis:/data -p 6379:6379 \
 --restart="always" \
 --name myredis redis:3.0.3 redis-server /usr/local/etc/redis/redis.conf
  • On docker host, create data volume so we aren’t reading/writing on the container:
    make sure this path is in the redis.conf file
  • sudo mkdir /data/redis && sudo chown ubuntu:docker $_ && sudo chmod g+w $_

  • if you get this warning:
    WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command ‘echo never > /sys/kernel/mm/transparent_hugepage/enabled’ as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
    > update Docker host:
    echo never > /sys/kernel/mm/transparent_hugepage/enabled

  • redis force save data file to disk command to test external volume:

    security issues:

  • add authentication if needed and check it on remote clients
  • set firewall: (ubuntu example where eth1 is LAN)
    ufw allow in on eth1 to any port 6379 proto tcp

    If you want to bake-in your config file or set other customizations, create Dockerfile:

    FROM redis:3.0.3
    COPY ./redis.conf /usr/local/etc/redis/redis.conf
  • Debian ‘ps’ command from Apt

    A lot of minimal Debian distros don’t have the `ps` process status app by default. There are times it’s useful when you want to inspect a container from the inside, so add:

    `apt-get install -y procps`

    to your build or manually install it after. Adds about 1MB to your environment.

    PHP 7 from Docker container complete with Yii 2.0

    Pretty cool, a PHP 7.0 (RC4) with Apache environment on Mac from scratch in a few minutes via Docker container:

    Includes installation for minimal requirements to support Yii 2.0

    Uses Vagrant + VirtualBox on Mac (or similar) or instead you can use any existing Docker host.

    Regex to extract text of C-style comments

    I needed to extract comments from some files to use for documentation and settled on the below two regex flavors (which you use depends on the tool / programming language). Requirement was to match on the whole document as many times as comments appeared and only match the text and comments in case of mixed code and comments on one line.

    You could extend this further by adding tokens to only fetch certain comments.

    First version is for gnu-grep that accepts the “global” and “single-line” pcre (Perl Compatible Regular Expressions) modifiers:

    \/ matches the character / literally
    \* matches the character * literally
    .*? matches any character
    Quantifier: *? Between zero and unlimited times, as few times as possible, expanding as needed [lazy]
    \* matches the character * literally
    \/ matches the character / literally
    g modifier: global. All matches (don't return on first match)
    s modifier: single line. Dot matches newline characters


    Second is for cases you can’t use the prior, like some terminal apps:

    From the command line, use:

    pcregrep -M -o "\/\*[\s\S]*?\*\/" File.php

    Where the “-M” does multiline searching, “-o” only returns the matching part of the line, and the “[\s\S]” matches any character including line breaks.

    Use sudo with echo in shell

    You can’t use sudo directly with echo in shell scripts / command line, so you need to use tee with append (-a). For example (simplified script example to update /etc/hosts for localhost entries):

    if [ $(cat /etc/hosts | egrep -c "\s$1") == 0 ]; then
    	echo " $1" | sudo tee -a /etc/hosts

    Yum update only security-related packages

    yum -y install yum-plugin-security

    # To display all updates that are security relevant, and get a reutrn code on whether there are security updates enter:
    yum --security check-update

    # To upgrade packages that have security errata (upgrades to the latest available package) use:
    yum --security update

    # To upgrade packages that have security errata (upgrades to the last security errata package) use:
    yum --security update-minimal

    # See yum-security man page for more information:
    man 8 yum-security

    thanks, cyberciti

    « Previous Entries