简介
由于版本的需求,需要编译使用新版本的redis。
准备基础镜像
dockerimporthttps://mirrors.aliyun.com/alpine/v3.15/releases/x86_64/alpine-minirootfs-3.15.0-x86_64.tar.gzalpine: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-modeneedpassword!!!!" exit1 fi cat>/etc/redis.conf<<EOF bind0.0.0.0 protected-mode${protected_mode} port${port} daemonizeno pidfile${data_dir}/redis_${port}.pid loglevelnotice logfile"${data_dir}/${port}.log" databases16 dbfilenamedump_${port}.rdb dir${data_dir} maxmemory$maxmemory appendonlyyes appendfilename"appendonly_${port}.aof" appendfsynceverysec requirepass"${password}" EOF /usr/local/bin/redis-server/etc/redis.conf
Dockerfile
#!/bin/bash cat>Dockerfile<<EOF Fromalpine:3.15.0 ADDhttps://download.redis.io/releases/redis-6.2.6.tar.gz/ RUNsed-i's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g'/etc/apk/repositories&&apkaddmakegccg++linux-headerstar&&tarzxvfredis-6.2.6.tar.gz&&cdredis-6.2.6&&make&&makeinstall&&apkdelmakegccg++linux-headerstar&&rm-rfv/redis-6.2.6/redis-6.2.6.tar.gz ADDentrypoint.sh/ ENTRYPOINT["/bin/sh","/entrypoint.sh"] EOF dockerbuild-tredis:v6.2.6.
使用
dockerrun-itd-ePASSWORD=123-ePORT=7000-eMAXMEMORY=5gb-ePROMTECTEDMODE=yes-eDATADIR=/data/redisredis:v6.2.6
支持变量:
- PASSWORD:密码
- PORT:端口
- MAXMEMORY:最大内存
- PROMTECTEDMODE:保护模式(默认是:no)
- DATADIR:数据目录
转载请注明:IT运维空间 » 运维技术 » 一文教你如何构建 Redis Docker镜像
继续浏览有关 Redis 的文章
发表评论