1,redis的dockerfile编写
#redis专用dockerfile
FROM centos:7.2.1511
MAINTAINER zzli
ENV REFRESHED_AT 2017-12-19
ENV REDIS_HOME /opt/redis/redis
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
ADD redis-3.2.9.tar.gz /opt/redis/
RUN ln -s /opt/redis/redis-3.2.9 $REDIS_HOME
RUN yum -y install gcc make
RUN mkdir -p /etc/redis/
WORKDIR $REDIS_HOME
RUN make && make install
EXPOSE 6379
EXPOSE 26379
ADD redis.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/redis.sh
ENTRYPOINT ["/usr/local/bin/redis.sh"]
提交镜像
docker build . -t phj/redis:0.1
2,redis-sentinel的dockerfile编写
#redis专用dockerfile
FROM centos:7.2.1511
MAINTAINER zzli
ENV REFRESHED_AT 2017-12-19
ENV REDIS_HOME /opt/redis/redis
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
ADD redis-3.2.9.tar.gz /opt/redis/
RUN ln -s /opt/redis/redis-3.2.9 $REDIS_HOME
RUN yum -y install gcc make
RUN mkdir -p /etc/redis/
WORKDIR $REDIS_HOME
RUN make && make install
EXPOSE 26379
ENTRYPOINT ["/usr/local/bin/redis-sentinel", "/etc/redis/sentinel.conf"]
提交镜像
docker build . -t phj/redis-sentinel:0.1
3,编写docker-compose启动redis集群
master1:
image: phj/redis:0.2
environment:
HOSTNAME: redis-master
container_name: redis1
ports:
- "6379:6379"
volumes:
- /redis/conf/master/:/etc/redis/
slave1:
image: phj/redis:0.2
environment:
HOSTNAME: redis-slave
ports:
- "6380:6379"
container_name: redis2
volumes:
- /redis/conf/slave/:/etc/redis/
links:
- master1:redis-master
sentinel1:
image: phj/redis-sentinel:0.1
expose:
- 26379
links:
- master1:redis-master
- slave1:redis-slave
environment:
HOSTNAME: redis-sentinel
container_name: redis-sentinel
volumes:
- /redis/conf/sentinel/:/etc/redis/
** 4,启动docker-compose**
docker up -d
5,redis.sh脚本如下:
#!/bin/bash
/usr/local/bin/redis-server /etc/redis/redis.conf
/usr/local/bin/redis-sentinel /etc/redis/sentinel.conf
网友评论