docker 安装 redis
[root@localhost ~]# docker pull redis:latest # 最新版本的镜像
latest: Pulling from library/redis
Digest: sha256:db485f2e245b5b3329fdc7eff4eb00f913e09d8feb9ca720788059fdc2ed8339
Status: Image is up to date for redis:latest
docker.io/library/redis:latest
[root@localhost ~]# docker images # 查看本地镜像
REPOSITORY TAG IMAGE ID CREATED SIZE
redis latest 7614ae9453d1 9 months ago 113MB
[root@localhost bin]# docker run -itd --name redis-test -p 6379:6379 redis # 运行容器
70463da02fbb2437c288aa2259760280b23a7c884d75509ee73535f3aa963732
[root@localhost bin]# docker ps # 查看运行容器
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
70463da02fbb redis "docker-entrypoint.s…" 12 seconds ago Up 11 seconds 0.0.0.0:6379->6379/tcp, :::6379->6379/tcp redis-test
[root@localhost bin]# docker exec -it redis-test /bin/bash # 连接测试使用 redis 服务
root@70463da02fbb:/data# redis-cli # 连接 redis 客户端
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> set test 1
OK
127.0.0.1:6379> get test
"1"
127.0.0.1:6379>
参数说明:
- -p 6379:6379:映射容器服务的 6379 端口到宿主机的 6379 端口。外部可以直接通过宿主机ip:6379 访问到 Redis 的服务
参考文档
Docker 安装 Redis | 菜鸟教程 (runoob.com)
标签:root,redis,6379,test,docker,安装,localhost From: https://www.cnblogs.com/liuzonglin/p/16754236.html