docker 安装redis

方法一、docker pull redis:3.2

查找Docker Hub上的redis镜像

runoob@runoob:~/redis$ docker search  redis
NAME                      DESCRIPTION                   STARS  OFFICIAL  AUTOMATED
redis                     Redis is an open source ...   2321   [OK]       
sameersbn/redis                                         32                   [OK]
torusware/speedus-redis   Always updated official ...   29             [OK]
bitnami/redis             Bitnami Redis Docker Image    22                   [OK]
anapsix/redis             11MB Redis server image ...   6                    [OK]
webhippie/redis           Docker images for redis       4                    [OK]
clue/redis-benchmark      A minimal docker image t...   3                    [OK]
williamyeh/redis          Redis image for Docker        3                    [OK]
unblibraries/redis        Leverages phusion/baseim...   2                    [OK]
greytip/redis             redis 3.0.3                   1                    [OK]
servivum/redis            Redis Docker Image            1                    [OK]
...

这里我们拉取官方的镜像,标签为3.2

runoob@runoob:~/redis$ docker pull  redis:3.2

等待下载完成后,我们就可以在本地镜像列表里查到REPOSITORY为redis,标签为3.2的镜像。

runoob@runoob:~/redis$ docker images redis 
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
redis               3.2                 43c923d57784        2 weeks ago         193.9 MB



使用redis镜像

运行容器

runoob@runoob:~/redis$  docker run -p 6679:6379 --name redis  -v $PWD/data:/data  -d redis:5.0 redis-server --appendonly yes --requirepass "789"
43f7a65ec7f8bd64eb1c5d82bc4fb60e5eb31915979c4e7821759aac3b62f330
runoob@runoob:~/redis$

命令说明:

-p 6679:6379 : 将容器的6379端口映射到主机的6679端口

-v $PWD/data:/data : 将主机中当前目录下的data挂载到容器的/data

redis-server --appendonly yes : 在容器执行redis-server启动命令,并打开redis持久化配置

--requirepass "789" 设置密码

查看容器启动情况

runoob@runoob:~/redis$ docker ps
CONTAINER ID   IMAGE        COMMAND                 ...   PORTS                      NAMES
43f7a65ec7f8   redis:3.2    "docker-entrypoint.sh"  ...   0.0.0.0:6379->6379/tcp     agitated_cray

连接、查看容器

使用redis镜像执行redis-cli命令连接到刚启动的容器,主机IP为172.17.0.1

runoob@runoob:~/redis$ docker exec -it 43f7a65ec7f8 redis-cli
172.17.0.1:6379> info
# Server
redis_version:3.2.0
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:f449541256e7d446
redis_mode:standalone
os:Linux 4.2.0-16-generic x86_64
arch_bits:64
multiplexing_api:epoll
...
 
posted @ 2019-06-07 19:59  Mr.DongYang  阅读(685)  评论(0编辑  收藏  举报