[toc]
root@ubuntu:/# docker run -d -P redis
cdf1868c4e5eb285c152d06637aec9a02e5ffdefe0772e615546c93655e52aff
root@ubuntu:/# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cdf1868c4e5e redis "docker-entrypoint.s…" 13 seconds ago Up 12 seconds 0.0.0.0:49157->6379/tcp, :::49157->6379/tcp wonderful_noyce
1ff6de0064bd mysql:5.7 "docker-entrypoint.s…" 3 minutes ago Up 3 minutes 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql_beifen
22e49c33a330 billygoo/tomcat8-jdk8 "catalina.sh run" 50 minutes ago Up 50 minutes 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp tomcat03
9e194dbf7eca tomcat "catalina.sh run" About an hour ago Up About an hour 0.0.0.0:49153->8080/tcp, :::49153->8080/tcp tomcat02
c6b2169449f4 ubuntu "bash" 2 hours ago Up 2 hours ubuntu2
37d9f24e95a3 ubuntu "bash" 2 hours ago Up 2 hours u1
f19e7fbc3d18 v2fly/v2fly-core "/usr/bin/v2ray -con…" 2 hours ago Restarting (2) 9 seconds ago tcp
root@ubuntu:/# docker exec -it cdf1868c4e5e /bin/bash
root@cdf1868c4e5e:/data# redis-cli
127.0.0.1:6379> set k1 v1
OK
127.0.0.1:6379> get k1
"v1"
1. 在宿主机上面先新建目录redis
mkdir -p /redis/redis
2. 将一个redis.conf文件模板拷贝到/app/redis目录下
apt-get install redis
rz
查看我的redis配置文件路径
root@ubuntu:/etc/redis# ls
redis.conf
root@ubuntu:/etc/redis# pwd
/etc/redis
操作
mkdir -p /redis/redis
cp /etc/redis/redis.conf /redis/redis/
-
开启redis验证(服务器强烈建议)
requirepass 123
-
允许redis外地链接(必须)
# bind 127.0.0.1
-
将
daemonize yes
改为no
protected-mode no
-
开启redis数据持久化
appendonly yes
可选
docker run -p 6379:6379 --name myredi01 \
--privileged=true \
-v /redis/redis/redis.conf:/etc/redis/redis.conf \
-v /redis/redis/data:/data \
-d redis \
redis-server /etc/redis/redis.conf
docker run -p 6379:6379 --name myredi01 --priviledged=true -v /redis/redis/redis.conf:/etc/redis/redis.conf -v /redis/redis/data:/data -d redis redis-server /etc/redis/redis.conf
以前是/bin/bash
现在是redis-server