下载redis镜像
首先查看一下redis
是否正确:
docker search redis
显示:
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
redis Redis is an open source key-value store that… 9636 [OK]
bitnami/redis Bitnami Redis Docker Image 184 [OK]
grokzen/redis-cluster Redis cluster 3.0, 3.2, 4.0, 5.0, 6.0, 6.2 78
rediscommander/redis-commander Alpine image for redis-commander - Redis man… 61 [OK]
redislabs/redisearch Redis With the RedisSearch module pre-loaded… 34
redislabs/redisinsight RedisInsight - The GUI for Redis 32
redislabs/redis Clustered in-memory database engine compatib… 31
oliver006/redis_exporter Prometheus Exporter for Redis Metrics. Supp… 28
.....
然后把redis
拉到本地就好:
docker pull redis
然后运行:
docker images
可以看到多了一个:redis latest 08502081bff6 8 days ago 105MB
运行docker redis
这个docker的id是08502081bff6
,所以首先运行这个镜像到容器中:
docker run -dit 08502081bff6
然后查看容器:
docker ps
可以看到:063c45279282 08502081bff6 "docker-entrypoint.s…" 2 seconds ago Up 2 seconds 6379/tcp fervent_wu
,其中容器ID为063c45279282
,
所以进入这个容器:
docker exec -it 063c45279282 /bin/bash
然后就是docker
里redis
的命令行了
启动与运行redis命令
启动redis
:
redis-server
如果是docker中,会发现服务 已经启动了:
40:C 02 Jul 2021 12:29:03.373 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
40:C 02 Jul 2021 12:29:03.374 # Redis version=6.2.4, bits=64, commit=00000000, modified=0, pid=40, just started
40:C 02 Jul 2021 12:29:03.374 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
40:M 02 Jul 2021 12:29:03.376 * monotonic clock: POSIX clock_gettime
40:M 02 Jul 2021 12:29:03.376 # Warning: Could not create server TCP listening socket *:6379: bind: Address already in use
40:M 02 Jul 2021 12:29:03.377 # Failed listening on port 6379 (TCP), aborting.
这样就已经启动redis
了,最后运行:
redis-cli
就是redis数据库的命令行了!