Redis 镜像打入指定依赖

编写 compose

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
vim docker-compose.yml

version: "3.9"
services:
redis:
image: redis:testv1
container_name: redismod
hostname: redis.server.csm.io
volumes:
- ./data:/data
- ./redis.conf:/etc/redis.conf
- ./users.acl:/etc/users.acl
entrypoint: ["redis-server", "/etc/redis.conf"]
ports:
- 6379:6379
restart: always

networks:
default:
external:
name: open-network

编写配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
vim redis.conf 

# requirepass 设置的为默认管理员的密码,它的默认用户名为 default
# acl 中的密码可以用 > 指定明文密码,比如
# acl setuser 用户名 >明文密码
# 也可以使用 # 指定 sha256 后的密码(echo -n "您的密码" | shasum -a 256),比如
# acl setuser 用户名 #sha256后的密码
# 当使用了 aclfile 时,验证密码时,必须加上用户名,比如
# auth default FI3jF7wKi4N4Jzy592zj2fPgOYg

aclfile /etc/users.acl
dir /data
#requirepass 123456
notify-keyspace-events Ex
#loadmodule /usr/lib/redis/modules/redisai.so
loadmodule /usr/lib/redis/modules/redisbloom.so
1
2
3
vim users.acl

user root on #56b7f54b03fec1xxxxxxxxd19713b64d41f95f42c98c76exxxe8d817axxx785b ~* +@all
1
mkdir data

编译依赖

Redisbool 依赖

1
2
3
4
5
6
7
8
9
10
11
# 下载源码包
wget https://github.com/RedisBloom/RedisBloom/archive/refs/tags/v2.2.12.zip
unzip v2.2.12.zip && cd RedisBloom-2.2.12/

# 编译
yum install gcc -y
make

# cv .so依赖,放入 Dockerfile 相对路径
cp redisbloom.so ../

制作 Redismod 镜像

编写 Dockerfile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
vim Dockerfile

ARG REDIS_VER=7.0.5
ARG ARCH=x64
ARG OSNICK=bullseye

FROM redisfab/redis:${REDIS_VER}-${ARCH}-${OSNICK}

ENV LD_LIBRARY_PATH /usr/lib/redis/modules
ENV REDISGEARS_MODULE_DIR /var/opt/redislabs/lib/modules
ENV REDISGEARS_PY_DIR /var/opt/redislabs/modules/rg
ENV REDISGRAPH_DEPS libgomp1 git

WORKDIR /data
RUN apt-get update -qq
RUN apt-get upgrade -y
RUN apt-get install -y --no-install-recommends ${REDISGRAPH_DEPS};
RUN rm -rf /var/cache/apt

COPY ./redisbloom.so /usr/lib/redis/modules/redisbloom.so

# ENV PYTHONPATH /usr/lib/redis/modules/deps/cpython/Lib
ENTRYPOINT ["redis-server"]
CMD ["--loadmodule", "/usr/lib/redis/modules/redisbloom.so", \
"Plugin", "/var/opt/redislabs/modules/rg/plugin/gears_python.so"]

build 镜像

1
docker build -t redis:testv1 .

启动容器

1
docker-compose up -d