简介
由于版本的需求,需要编译使用新版本的redis。
准备基础镜像
- docker import https://mirrors.aliyun.com/alpine/v3.15/releases/x86_64/alpine-minirootfs-3.15.0-x86_64.tar.gz alpine:3.15.0
启动文件
- #!/bin/sh
- set -e
- port=6379
- if [ "$PORT" != "" ] ; then
- port=$PORT
- fi
- data_dir=/data/redis/data
- if [ "$DATADIR" != "" ] ; then
- data_dir=$DATADIR
- fi
- mkdir -p $data_dir
- password=""
- if [ "$PASSWORD" != "" ] ; then
- password=$PASSWORD
- fi
- maxmemory=0
- if [ "$MAXMEMORY" != "" ] ; then
- maxmemory=$MAXMEMORY
- fi
- protected_mode="no"
- if [ "$PROTECTEDMODE" != "" ] ; then
- protected_mode=$PROTECTEDMODE
- fi
- if [[ "$PASSWORD" == "" && "$protected_mode" == "yes" ]]; then
- echo "protected-mode need password!!!!"
- exit 1
- fi
- cat >/etc/redis.conf <<EOF
- bind 0.0.0.0
- protected-mode ${protected_mode}
- port ${port}
- daemonize no
- pidfile ${data_dir}/redis_${port}.pid
- loglevel notice
- logfile "${data_dir}/${port}.log"
- databases 16
- dbfilename dump_${port}.rdb
- dir ${data_dir}
- maxmemory $maxmemory
- appendonly yes
- appendfilename "appendonly_${port}.aof"
- appendfsync everysec
- requirepass "${password}"
- EOF
- /usr/local/bin/redis-server /etc/redis.conf
Dockerfile
- #!/bin/bash
- cat >Dockerfile <<EOF
- From alpine:3.15.0
- ADD https://download.redis.io/releases/redis-6.2.6.tar.gz /
- RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && apk add make gcc g++ linux-headers tar && tar zxvf redis-6.2.6.tar.gz && cd redis-6.2.6 && make && make install && apk del make gcc g++ linux-headers tar && rm -rfv /redis-6.2.6 /redis-6.2.6.tar.gz
- ADD entrypoint.sh /
- ENTRYPOINT [ "/bin/sh","/entrypoint.sh" ]
- EOF
- docker build -t redis:v6.2.6 .
使用
- docker run -itd -e PASSWORD=123 -e PORT=7000 -e MAXMEMORY=5gb -e PROMTECTEDMODE=yes -e DATADIR=/data/redis redis:v6.2.6
支持变量:
- PASSWORD:密码
- PORT:端口
- MAXMEMORY:最大内存
- PROMTECTEDMODE:保护模式(默认是:no)
- DATADIR:数据目录