37.5 docker linux centos 7 redis 安装
37.5.0 需要一个 centos-ssh-root
37.5.1 编辑 dockerfile
############################################
# version : curiousby/redis-4.0.1
# desc : 当前版本安装的redis-4.0.1
############################################
# 设置继承自我们创建的 tools 镜像
FROM curiousby/centos-ssh-root:original
# 下面是一些创建者的基本信息
MAINTAINER curiousby (curiousby@163.com)
# 复制 redis-4.0.1 文件到镜像中
ADD redis-4.0.1 /usr/local/redis-4.0.1
RUN ln -s /usr/local/redis-4.0.1 /usr/local/redis
# 设置 redis 的环境变量
ENV REDIS_HOME /usr/local/redis
ENV LC_ALL C
#容器需要开放Redis 6379端口
EXPOSE 6379
RUN mkdir -p /etc/redis/
COPY redis.conf /etc/redis/redis.conf
COPY autorun.sh /etc/redis/autorun.sh
RUN chmod u+x /etc/redis/autorun.sh
# 执行路径启动服务。
#CMD ["/usr/local/redis-4.0.1/src/redis-server /etc/redis/redis.conf"]
37.5.3 修改 redis.conf 到当前路劲
daemonize yes //设置后台启动
protected-mode no //设置非保护模式
#bind 127.0.0.1 //设置非绑定本地
37.5.4 设置自启动脚本
#!/bin/bash
source ~/.bashrc
/usr/local/redis/src/redis-server /etc/redis/redis.conf
37.5.5 执行命令
docker build -t curiousby/centos-ssh-root-redis:original .
docker run -d curiousby/centos-ssh-root-redis:original
docker exec -it e0 bash
进入容器内部,编译安装
yum -y install gcc automake autoconf libtool make
yum install -y gcc gcc-c++
cd /usr/local/redis
make
make install
docker commit e00 curiousby/centos-ssh-root-redis:original
docker stop e00
docker run -d -p 6379:6379 curiousby/centos-ssh-root-redis:original
docker exec -it 2a3b bash
/etc/redis/autorun.sh
37.5.6 日志
37.5.6.1 bulid 日志
[root@localhost centos-ssh-root-redis]# docker build -t curiousby/centos-ssh-root-redis:original .
Sending build context to Docker daemon 9.342MB
Step 1/11 : FROM curiousby/centos-ssh-root:original
---> c8be7759c979
Step 2/11 : MAINTAINER curiousby (curiousby@163.com)
---> Running in 97b11ac19651
---> d0809e2db1bc
Removing intermediate container 97b11ac19651
Step 3/11 : ADD redis-4.0.1 /usr/local/redis-4.0.1
---> 095e55922133
Removing intermediate container 97cb5c1369b9
Step 4/11 : RUN ln -s /usr/local/redis-4.0.1 /usr/local/redis
---> Running in ec31c1e694d2
---> 9e827420fd8f
Removing intermediate container ec31c1e694d2
Step 5/11 : ENV REDIS_HOME /usr/local/redis
---> Running in 48c20ffc6c06
---> cf6e3c2ab921
Removing intermediate container 48c20ffc6c06
Step 6/11 : ENV LC_ALL C
---> Running in b6907377fede
---> d04419229e50
Removing intermediate container b6907377fede
Step 7/11 : EXPOSE 6379
---> Running in a07865b08dce
---> 1f3b71f7f4e4
Removing intermediate container a07865b08dce
Step 8/11 : RUN mkdir -p /etc/redis/
---> Running in 60953230beba
---> dc560129770f
Removing intermediate container 60953230beba
Step 9/11 : COPY redis.conf /etc/redis/redis.conf
---> b62219be6a36
Removing intermediate container 7d77e59f0bd4
Step 10/11 : COPY autorun.sh /etc/redis/autorun.sh
---> 8635d2862a3e
Removing intermediate container 6985530b0a9e
Step 11/11 : RUN chmod u+x /etc/redis/autorun.sh
---> Running in 6f87a73e7c93
---> fa0ab9d4f98c
Removing intermediate container 6f87a73e7c93
Successfully built fa0ab9d4f98c
Successfully tagged curiousby/centos-ssh-root-redis:original
37.5.6.2 编译安装日志
make
make install
run
ps: 本人写的自启动脚本不能启动,不然就可以自启动了,不需要去容器内部启动,有知道的可以告诉我一下 docker run -d -p 6379:6379 curiousby/centos-ssh-root-redis:original /etc/redis/autorun.sh
感谢下方留言。。。
37.5.7 测试
package com.baoy.cn.redis;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
public class RedisTest {
private static Jedis jedis;//非切片额客户端连接
private static JedisPool jedisPool;//非切片连接池
public static void main(String[] args) {
JedisPoolConfig config = new JedisPoolConfig();
config.setMaxIdle(20);
config.setMaxIdle(5);
config.setMaxWaitMillis(1000l);
config.setTestOnBorrow(false);
jedisPool = new JedisPool(config,"192.168.206.238",6379);
jedis = jedisPool.getResource();
jedis.set("key001","value001");
System.out.println(jedis.get("key001"));
}
}
捐助开发者
在兴趣的驱动下,写一个免费
的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(支持支付宝和微信 以及扣扣群),没钱捧个人场,谢谢各位。
个人主页:http://knight-black-bob.iteye.com/
谢谢您的赞助,我会做的更好!