做个记录 MacOS 安装 Docker Redis。

安装 Docker

  省略

查找镜像

1
2
3
4
5
6
zhoupqcom:~ zhoupq$ docker search redis
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
redis Redis is an open source key-value store that… 5616 [OK]
bitnami/redis Bitnami Redis Docker Image 87 [OK]
sameersbn/redis 71 [OK]
hypriot/rpi-redis Raspberry Pi compatible redis image 32

拉取镜像

1
docker pull redis:latest

验证镜像

1
2
3
zhoupqcom:~ zhoupq$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
redis latest 4e8db158f18d 2 weeks ago 83.4MB

创建、启动镜像

1
2
3
zhoupqcom:~ mkdir redis
zhoupqcom:redis zhoupq$ docker run -p 6379:6379 -v $PWD/data:/data -d redis:latest redis-server
a7c8b8fddbbb9b5e41680454a38bdb1d43e08aa1555e833c03676f2fd04fef19

验证容器启动

1
2
3
zhoupqcom:~ zhoupq$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a7c8b8fddbbb redis:latest "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 0.0.0.0:6379->6379/tcp elegant_euclid

连接容器

1
2
zhoupqcom:redis zhoupq$ docker run -it redis:latest redis-cli -h 本机IP地址 --raw
本机IP地址:6379>

关闭容器

1
2
3
4
5
zhoupqcom:~ zhoupq$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a7c8b8fddbbb redis:latest "docker-entrypoint.s…" 14 minutes ago Up 14 minutes 0.0.0.0:6379->6379/tcp elegant_euclid
zhoupqcom:~ zhoupq$ docker kill a7c8b8fddbbb
a7c8b8fddbbb

参考

  1. 如何使用Docker安装Redis\Zookeeper\Mysql
  2. Docker 入门教程
  3. Docker run 命令
  4. Docker 安装 Redis