查询镜像: docker search redis
[root@iZbp1ab9p10tmbii6x7z0oZ ~]# docker search redis
INDEX NAME DESCRIPTION STARS OFFICIAL AUTOMATED
docker.io docker.io/redis Redis is an open source key-value store th... 7469 [OK]
docker.io docker.io/bitnami/redis Bitnami Redis Docker Image 130 [OK]
docker.io docker.io/sameersbn/redis 78 [OK]
docker.io docker.io/grokzen/redis-cluster Redis cluster 3.0, 3.2, 4.0 & 5.0 61
docker.io docker.io/rediscommander/redis-commander Alpine image for redis-commander - Redis m... 31 [OK]
docker.io docker.io/kubeguide/redis-master redis-master with "Hello World!" 30
docker.io docker.io/redislabs/redis Clustered in-memory database engine compat... 24
docker.io docker.io/arm32v7/redis Redis is an open source key-value store th... 17
docker.io docker.io/oliver006/redis_exporter Prometheus Exporter for Redis Metrics. Su... 17
docker.io docker.io/redislabs/redisearch Redis With the RedisSearch module pre-load... 17
docker.io docker.io/webhippie/redis Docker images for Redis 10 [OK]
拉取官方的镜像:会自动拉取stars标星最多的镜像 docker pull redis
[root@iZbp1ab9p10tmbii6x7z0oZ ~]# docker pull redis
Using default tag: latest
Trying to pull repository docker.io/library/redis ...
latest: Pulling from docker.io/library/redis
8d691f585fa8: Pull complete
8ccd02d17190: Pull complete
4719eb1815f2: Pull complete
200531706a7d: Pull complete
eed7c26916cf: Pull complete
e1285fcc6a46: Pull complete
Digest: sha256:c6b7e6bd9e234221509e0ebc90ad89ff491e61a604a4eb2649570e9703fafc65
Status: Downloaded newer image for docker.io/redis:latest
查看一下是否成功:docker images
启动镜像:docker run -p 6379:6379 -v $PWD/data:/data -d redis:3.2 redis-server --appendonly yes
命令说明:
-p 6379:6379 : 将容器的6379端口映射到主机的6379端口 -v $PWD/data:/data : 将主机中当前目录下的data挂载到容器的/data redis-server --appendonly yes : 在容器执行redis-server启动命令,并打开redis持久化配置
[root@iZbp1ab9p10tmbii6x7z0oZ ~]# docker run -p 6379:6379 -v $PWD/data:/data -d redis:3.2 redis-server --appendonly yes
Unable to find image 'redis:3.2' locally
Trying to pull repository docker.io/library/redis ...
3.2: Pulling from docker.io/library/redis
f17d81b4b692: Pull complete
b32474098757: Pull complete
8980cabe8bc2: Pull complete
58af19693e78: Pull complete
a977782cf22d: Pull complete
9c1e268980b7: Pull complete
Digest: sha256:562e944371527d6e11d396fe43fde17c30e28c25c23561b2322db3905cbc71dd
Status: Downloaded newer image for docker.io/redis:3.2
82807224f0c5eb16c8a416649eee7c6f8d963ffa1717c15f1c75cbc91e990d2b
查看容器启动情况:docker ps
连接redis: 可使用redis desktop manager,如果redis已经启动起来了,但是外部连接不上,请查看redis对应的端口(6379)是否开放.
查看容器的ip: docker inspect container_id | grep IPAddress (container_id:为容器对应id)