FROM centos:8 ENV REDIS_VERSION 6.2.2 ENV PORT_01 9001 ENV PORT_02 9002 ENV PORT_03 9003 ENV PORT_04 9004 ENV PORT_05 9005 ENV PORT_06 9006 RUN yum -y update RUN yum install -y wget RUN yum install -y gcc gcc-c++ make RUN mkdir /redis RUN cd /redis\ && wget https://download.redis.io/releases/redis-${REDIS_VERSION}.tar.gz -O redis.tar.gz\ && mkdir -p redis \ && tar -zvxf redis.tar.gz \ && rm -rf redis.tar.gz\ && cd redis-${REDIS_VERSION}\ && make ## 建立集群目录 RUN mkdir /redis/redis01 /redis/redis02 /redis/redis03 /redis/redis04 /redis/redis05 /redis/redis06 ## 复制redis文件 RUN cp /redis/redis-${REDIS_VERSION}/{redis.conf,src/redis-server,src/redis-cli} /redis/redis01/ ## 修改监听地址 RUN sed -i "s/\\(^bind.*\\)/\\#\\1\\nbind 0.0.0.0/" /redis/redis01/redis.conf ## 开启集群配置 RUN sed -i "s/\\(^\\#.\*cluster-enabled yes.\*\\)/\\\ncluster-enabled yes/" /redis/redis01/redis.conf RUN sed -i "s/\\(^daemonize.*\\)/\\daemonize yes/" /redis/redis01/redis.conf RUN cp -rf /redis/redis01/* /redis/redis02/\ && cp -rf /redis/redis01/* /redis/redis03/\ && cp -rf /redis/redis01/* /redis/redis04/\ && cp -rf /redis/redis01/* /redis/redis05/\ && cp -rf /redis/redis01/* /redis/redis06/ RUN sed -i "s/\\(^port.*\\)/\\#\\1\\nport ${PORT_01}/" /redis/redis01/redis.conf RUN sed -i "s/\\(^port.*\\)/\\#\\1\\nport ${PORT_02}/" /redis/redis02/redis.conf RUN sed -i "s/\\(^port.*\\)/\\#\\1\\nport ${PORT_03}/" /redis/redis03/redis.conf RUN sed -i "s/\\(^port.*\\)/\\#\\1\\nport ${PORT_04}/" /redis/redis04/redis.conf RUN sed -i "s/\\(^port.*\\)/\\#\\1\\nport ${PORT_05}/" /redis/redis05/redis.conf RUN sed -i "s/\\(^port.*\\)/\\#\\1\\nport ${PORT_06}/" /redis/redis06/redis.conf WORKDIR /redis CMD cd /redis/redis01 && /redis/redis01/redis-server /redis/redis01/redis.conf;\ && cd /redis/redis02 && /redis/redis02/redis-server /redis/redis02/redis.conf;\ && cd /redis/redis03 && /redis/redis03/redis-server /redis/redis03/redis.conf;\ && cd /redis/redis04 && /redis/redis04/redis-server /redis/redis04/redis.conf;\ && cd /redis/redis05 && /redis/redis05/redis-server /redis/redis05/redis.conf;\ && cd /redis/redis06 && /redis/redis06/redis-server /redis/redis06/redis.conf; CMD /redis/redis01/redis-cli --cluster create 127.0.0.1:${PORT\_01} 127.0.0.1:${PORT\_02} 127.0.0.1:${PORT\_03} 127.0.0.1:${PORT\_04} 127.0.0.1:${PORT\_05} 127.0.0.1:${PORT\_06} --cluster-replicas 1 EXPOSE ${PORT\_01} ${PORT\_02} ${PORT\_03} ${PORT\_04} ${PORT\_05} ${PORT\_06}