本文主要是介绍Docker 安装 Redis 并配置 Docker 方式的 phpRedisAdmin,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Redis 官方image
redis Official Image
官方安装文档没有 Docker 方式
Redis Quick Start
phpredisadmin
erikdubbelboer/phpRedisAdmin
这是 gitee 镜像
Gitee 极速下载 / phpredisadmin
Docker安装 redis
-
准备镜像
docker search redis
docker pull redis -
简单启动一个 redis 实例 (start a redis instance)
docker run --name redis-20211228 -d redis$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES8ec340137658 redis "docker-entrypoint.s…" 4 seconds ago Up 3 seconds 6379/tcp redis-20211228
$ docker inspect redis-20211228
可以看到,
- 没有映射6379 到宿主机任何端口,外部无法直接访问
- 挂载数据 /data 对应宿主机上 “Source”: “/var/lib/docker/volumes/ef4edf69fd8047ed59cb7ca2baf67613c68a49d250f9b2322d81709bd22264c5/_data”,
删除
$ docker rm redis-20211228 -f -
加上挂载宿主机目录,映射宿主机端口
$ mkdir data-redis/data -p
$ mkdir data-redis/conf -p检测 6379 端口是否被占用?
我这个宿主机之前已经二进制方式安装过 redis 和 phpRedisAdmin ,所以,一定是冲突的!
$ netstat -tunlp |grep 6379(Not all processes could be identified, non-owned process infowill not be shown, you would have to be root to see it all.)tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN - tcp 0 0 192.168.1.203:6379 0.0.0.0:* LISTEN - $ ss -tunlp |grep 6379tcp LISTEN 0 511 127.0.0.1:6379 0.0.0.0:* tcp LISTEN 0 511 192.168.1.203:6379 0.0.0.0:* $ sudo lsof -i:6379COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAMEredis-ser 629 redis 6u IPv4 23240 0t0 TCP ubuntu2004-203:6379 (LISTEN)redis-ser 629 redis 7u IPv4 23241 0t0 TCP localhost:6379 (LISTEN)
重新启动 redis-20211228 实例
docker run -it --name redis-20211228 -d -p 6378:6379 -v ~/data-redis/data:/data -v ~/data-redis/conf/redis.conf:/etc/redis/redis.conf redis redis-server --save 60 1 --loglevel warning
参数说明:
-
端口改在 6378
-
data 设置在 ~/data-redis/conf/redis.conf
-
配置文件放在 ~/data-redis/conf/redis.conf
-
-
检测容器信息
$ docker inspect redis-20211228..."Mounts": [{"Type": "bind","Source": "/home/dhbm/data-redis/data","Destination": "/data","Mode": "","RW": true,"Propagation": "rprivate"},{"Type": "bind","Source": "/home/dhbm/data-redis/conf/redis.conf","Destination": "/etc/redis/redis.conf","Mode": "","RW": true,"Propagation": "rprivate"}],..."Ports": {"6379/tcp": [{"HostIp": "0.0.0.0","HostPort": "6378"},{"HostIp": "::","HostPort": "6378"}]},
可以看到
容器数据挂载到 /data 目录 ,对应在宿主机上"Source": “/home/dhbm/data-redis/data”,
容器内端口 6379 对应到宿主机的 6378 端口 -
宿主机访问测试
$ redis-cli -p 6378
127.0.0.1:6378> -
进入到容器测试
$ docker exec -it redis-20211228 /bin/sh
# redis-cli127.0.0.1:6379>
-
远程访问测试
$ redis-cli -h 192.168.1.203 -p 6378
192.168.1.203:6378>
Docker 安装 phpRedisAdmin
-
找个没有占用的端口
$ sudo lsof -i:80[sudo] password for dhbm: COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAMEnginx 929 root 9u IPv4 24838 0t0 TCP *:http (LISTEN)nginx 930 www-data 9u IPv4 24838 0t0 TCP *:http (LISTEN)
-
摘录文档中关于参数的内容
Environment variables summary
REDIS_1_HOST - define host of the Redis server
REDIS_1_NAME - define name of the Redis server
REDIS_1_PORT - define port of the Redis server
REDIS_1_AUTH - define password of the Redis server
REDIS_1_DATABASES - You can modify you config to prevent phpRedisAdmin from using CONFIG command
ADMIN_USER - define username for user-facing Basic Auth
ADMIN_PASS - define password for user-facing Basic Auth -
为了对应前面 Docker 安装的 redis ,需要配置对应端口REDIS_1_PORT=6378
启动 phpredisadmin-20211228 实例
docker run -d --name --rm -it -e REDIS_1_HOST=192.168.1.203 -e REDIS_1_NAME=MyRedis -e REDIS_1_PORT=6378 -p 82:80 erikdubbelboer/phpredisadmin
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES3b9dffc86149 erikdubbelboer/phpredisadmin "tini -- php -S 0.0.…" 6 seconds ago Up 4 seconds 0.0.0.0:82->80/tcp, :::82->80/tcp phpredisadmin-202112281eb1ce42aa1b redis "docker-entrypoint.s…" 15 minutes ago Up 14 minutes 0.0.0.0:6378->6379/tcp, :::6378->6379/tcp redis-20211228...
-
访问验证
$ curl 127.0.0.1:82
$ curl 192.168.1.203:82 -
桌面电脑浏览器打开 http://192.168.1.203:82/?overview
-
重新启动一个 phpredisadmin 实例,用于对应宿主机上二进制安装的 redis
二进制安装的 redis 端口在 6379,无需再配置参数 REDIS_1_PORT
$ docker run -d --name phpredisadmin --rm -it -e REDIS_1_HOST=192.168.1.203 -e REDIS_1_NAME=MyRedis -p 81:80 erikdubbelboer/phpredisadmin
0cd69613adde8c574aaae06dd76ca521c403409907440d14bbdf48f14df01e68桌面电脑浏览器打开 http://192.168.1.203:81/?overview
这篇关于Docker 安装 Redis 并配置 Docker 方式的 phpRedisAdmin的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!