Docker安裝Redis
查找Redis
docker search Redis
完整結果
PS C:\Users\cheng> docker search Redis
NAME DESCRIPTION STARS OFFICIAL
redis Redis is an open source key-value store that… 12814 [OK]
redislabs/redisearch Redis With the RedisSearch module pre-loaded… 64
redislabs/redisinsight RedisInsight - The GUI for Redis 102
redis/redis-stack-server redis-stack-server installs a Redis server w… 76
redis/redis-stack redis-stack installs a Redis server with add… 106
redislabs/rebloom A probablistic datatypes module for Redis 27
redislabs/redis Clustered in-memory database engine compatib… 40
redislabs/rejson RedisJSON - Enhanced JSON data type processi… 53
redislabs/redismod An automated build of redismod - latest Redi… 47
redislabs/redisgraph A graph database module for Redis 27
redislabs/redistimeseries A time series database module for Redis 12
redislabs/operator 7
redislabs/operator-internal This repository contains pre-released versio… 1
拉取 Redis(最新版本)
docker pull redis:latest
查看鏡像列表
docker images
完整結果
PS C:\Users\cheng> docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
redis latest 9509c4dd19fb 5 weeks ago 116MB
運行容器
docker run -itd --name redis-v1 -p 6379:6379 redis
- -p 6379:6379:映射容器服務的 6379 端口到宿主機的 6379 端口。外部可以直接通過宿主機ip:6379 訪問到 Redis 的服務。
查看容器運行信息
docker ps
完整結果
PS C:\Users\cheng> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e74b17c983bf redis "docker-entrypoint.s…" 31 seconds ago Up 29 seconds 0.0.0.0:6379->6379/tcp redis-v1
測試Redis
執行容器
docker exec -it redis-v1 /bin/bash
完整結果
PS C:\Users\cheng> docker exec -it redis-v1 /bin/bash
root@e74b17c983bf:/data#
接著輸入 redis-cli
完整結果
PS C:\Users\cheng> docker exec -it redis-v1 /bin/bash
root@e74b17c983bf:/data# redis-cli
127.0.0.1:6379>
設置一個 key 和 value
PS C:\Users\cheng> docker exec -it redis-v1 /bin/bash
root@e74b17c983bf:/data# redis-cli
127.0.0.1:6379> set test 1
OK
127.0.0.1:6379> get test
"1"
127.0.0.1:6379> set test 1a
OK
127.0.0.1:6379> get test
"1a"
127.0.0.1:6379>
Visual Studio Code 安裝Redis工具
搜索 Redis
選擇第一個安裝
安裝完成后, 重啟vs code
點擊Database
點擊 Create Connection
創建一個新的連接
設置 名稱、主機名、端口、點擊保存,再點擊連接
下圖就是連接后的效果
當然,你也可以選擇編輯他
編輯的效果