Sign inSign up

mlawry/redis

By mlawry

•Updated almost 8 years ago

Redis cache 5.0.0 on Ubuntu 16.04

Image
0

1.7K

mlawry/redis repository overview

⁠The Image

Redis 5.0.0 is compiled and installed separately on a Ubuntu 16.04 computer.

$ sudo apt-get install build-essential tcl
$ wget http://download.redis.io/releases/redis-5.0.0.tar.gz
$ tar -xzvf redis-5.0.0.tar.gz
$ cd redis-5.0.0
$ make
$ make test
$ make PREFIX=/opt/redis install

. In a new directory, create the following Dockerfile:

FROM mlawry/ubuntu-xenial-nocmd:201810

# Install the /usr/bin/host command, which is required by the startredis.sh script.
RUN apt update && apt upgrade
RUN apt install -y bind9-host
RUN apt clean

# Copy precompiled redis binary to image.
COPY redis/ /opt/redis/
COPY startredis.sh /opt/redis/startredis.sh

# Create /data directory to store data.
RUN mkdir /data
EXPOSE 6379
ENTRYPOINT ["/bin/bash", "/opt/redis/startredis.sh"]

. Also create a bash script named startredis.sh to start redis with an appropriate configuration file.

#!/bin/bash
echo "protected-mode no"  >> /opt/redis/redis.conf
echo "dir /data"          >> /opt/redis/redis.conf
echo "logfile \"\""       >> /opt/redis/redis.conf

# Translate replica hostname to IP address.
if [ -n "$REDIS_HOSTNAME" ]; then
  REDIS_IP=`host -t A $REDIS_HOSTNAME | cut --delimiter=" " --fields=4 -`
  echo "replica-announce-ip $REDIS_IP" >> /opt/redis/redis.conf
fi

# Override default port for this redis node (applies to master and replica nodes).
if [ -z "$REDIS_PORT" ]; then
  echo "port 6379"        >> /opt/redis/redis.conf
else
  echo "port $REDIS_PORT" >> /opt/redis/redis.conf
fi

# Output replicaof for replica node. Do not default for master node.
if [ -n "$REDIS_MASTER_HOSTNAME" ]; then
  # Get master IP address using master's hostname.
  REDIS_MASTER_IP=`host -t A $REDIS_MASTER_HOSTNAME | cut --delimiter=" " --fields=4 -`

  # Use default port for master node if no override defined.
  if [ -z "$REDIS_MASTER_PORT" ]; then
    REDIS_MASTER_PORT=6379
  fi

  # Output replicaof line.
  echo "replicaof $REDIS_MASTER_IP $REDIS_MASTER_PORT" >> /opt/redis/redis.conf
fi

echo "Starting redis-server using configuration file"
echo "-----------------------------------"
cat /opt/redis/redis.conf
echo "-----------------------------------"

/opt/redis/bin/redis-server /opt/redis/redis.conf

. Copy the compiled binary into the current directory (required by Dockerfile).

$ cp -r /opt/redis ./redis

. The image is now built with:

sudo docker build -t mlawry/redis .
sudo docker push mlawry/redis:latest

.

⁠Environment Variables

Set the following environment variables to configure the image behaviour on start up.

REDIS_HOSTNAME (optional)

Hostname of the container instance, used by the startredis.sh script to get the container IP address, which is then used to output the replica-announce-ip $REDIS_IP configuration line. If not defined or empty, the configuration line is not added.

If you define this variable when redis is running as a master, then REDIS_IP will be announced as the master node's IP address. If redis is running as a replica, then REDIS_IP will be announced as the replica node's IP address.

REDIS_PORT (optional)

The port that the redis service is listening on. Used by startredis.sh to output the port $REDIS_PORT configuration line. If not defined or empty, the default port 6379 is used.

REDIS_MASTER_HOSTNAME (optional)

Hostname of the redis master node, used by the startredis.sh script to get the IP address to connect to redis master. Used to output the replicaof $REDIS_MASTER_IP $REDIS_MASTER_PORT configuration line. If not defined or empty, the configuration line is not added.

To run this redis instance as a master, do not define this variable. Defining this variable will force this instance to run as a replica.

REDIS_MASTER_PORT (optional)

Port of the redis master service, used by the startredis.sh script to output the replicaof $REDIS_MASTER_IP $REDIS_MASTER_PORT configuration line. If not defined or empty, the default port 6379 is used.

⁠Actual Configuration

When you run this image, the configuration created by the startredis.sh script is printed to standard output. The redis process also logs to standard output, using the logfile "" configuration line.

Tag summary

Content type

Image

Digest

Size

223.8 MB

Last updated

almost 8 years ago

docker pull mlawry/redis