Docker入门(四)- 搭建redis

搭建redis

1.下载redis镜像

➜  docker pull redis:3.2.8
5.7: Pulling from library/mysql
75a822cd7888: Pull complete
b8d5846e536a: Pull complete
b75e9152a170: Pull complete
832e6b030496: Pull complete
fe4a6c835905: Pull complete
c3f247e29ab1: Pull complete
21be3e562071: Pull complete
c7399d6bf033: Pull complete
ccdaeae6c735: Pull complete
713c7d65b0d3: Pull complete
86c18539deb2: Pull complete
Digest: sha256:9dc1cece2974c51a4b95bff634ad2b62d2c1225f825c9947cc403dec4f810a6e
Status: Downloaded newer image for mysql:5.7

2.部署redis

7001:6379 <=> 外部端口:docker容器端口, 本地${pwd}/redis.conf的bind配置项需要注意,如果是127.0.0.1,外部将无法连接docker内的redis

➜  docker run --name redis3.2.8 -p 7001:6379 -v ${pwd}/redis.conf:/etc/redis/redis.conf -d redis:3.2.8 redis-server --appendonly yes                                                         1 ↵
db6d62ec29e09b5183dc1c216ee57413a87330c122b96330f474eafd8ea83860

3.查看容器进程

➜  docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
db6d62ec29e0        redis:3.2.8         "docker-entrypoint..."   3 hours ago         Up 16 seconds       0.0.0.0:7001->6379/tcp   redis3.2.8
e41193fe394a        mysql:5.7           "docker-entrypoint..."   6 hours ago         Up 2 hours          0.0.0.0:3307->3306/tcp   mysql5.7

4.进入redis容器

➜  docker exec -ti db6d62ec29e0 /bin/bash
root@db6d62ec29e0:/data# redis-cli
127.0.0.1:6379> 
    原文作者:ellis
    原文地址: https://segmentfault.com/a/1190000009160589
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞