#docker 容器中拉取Redis镜像
$ docker pull redis:latest
[tingzhuxuan@localhost ~]$ docker pull redis:latest
latest: Pulling from library/redis
e5ae68f74026: Pull complete
37c4354629da: Pull complete
b065b1b1fa0f: Pull complete
6954d19bb2e5: Pull complete
6333f8baaf7c: Pull complete
f9772c8a44e7: Pull complete
Digest: sha256:2f502d27c3e9b54295f1c591b3970340d02f8a5824402c8179dcd20d4076b796
Status: Downloaded newer image for redis:latest
docker.io/library/redis:latest
###查看拉下来的Redis镜像
[tingzhuxuan@localhost ~]$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
redis latest aea9b698d7d1 5 days ago 113MB
hello-world latest feb5d9fea6a5 2 months ago 13.3kB
###-p 6379:6379:映射容器服务的 6379 端口到宿主机的 6379 端口。外部可以直接通过宿主机ip:6379 访问到 Redis 的服务
[tingzhuxuan@localhost ~]$ docker run -itd --name redis-test -p 6379:6379 redis
831a870806440b4d06276117ddf3a4ab8406c554bc47d2a1e2b66c30ced5e721
###过 docker ps 命令查看容器的运行信息
[tingzhuxuan@localhost ~]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
831a87080644 redis "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:6379->6379/tcp, :::6379->6379/tcp redis-test
###通过 redis-cli 连接测试使用 redis 服务。
[tingzhuxuan@localhost ~]$ docker exec -it redis-test /bin/bash
root@831a87080644:/data# set test 1