Dockerfile构建redis镜像
- 编写redis编译安装shell脚本redis_install.sh (最后两行的意思是,第69行匹配127.0.0.1更换成0.0.0.0;第88行匹配protected-mode yes更换为protected-mode no)
-
#!/bin/bash yum install -y gcc gcc-c++ make openssl openssl-devel cd /home/redis-4.0.9 make && make PREFIX=/usr/local/redis install mkdir -p /usr/local/redis/conf/ cp /home/redis-4.0.9/redis.conf /usr/local/redis/conf/ sed -i '69s/127.0.0.1/0.0.0.0/' /usr/local/redis/conf/redis.conf sed -i '88s/protected-mode yes/protected-mode no/' /usr/local/redis/conf/redis.conf
-
- 编写Dockerfile
-
FROM centos:7 ADD redis-4.0.9.tar.gz /home COPY redis_install.sh /home RUN sh /home/redis_install.sh ENTRYPOINT /usr/local/redis/bin/redis-server /usr/local/redis/conf/redis.conf
-
- 测试redis
- 启动容器 docker run -itd -p 6380:6379 mycentos:redis #6380为宿主机端口,6379为容器端口
- 进入容器 docker exec -it 镜像id /bin/bash
- 宿主机连接redis /usr/local/redis/bin/redis-cli -p 6380
- 验证:可以在宿主机set name xxx,然后在容器内get name 测试