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
  • Leave a Reply