美文网首页
# Docker安装redis 5.0.7并挂载外部配置和数据

# Docker安装redis 5.0.7并挂载外部配置和数据

作者: 努力耕耘少问收获 | 来源:发表于2020-09-14 11:18 被阅读0次
    拉取redis 5.0.7 镜像
    docker  pull redis:5.0.7
    
    [root@VM-0-2-centos byp]# 
    [root@VM-0-2-centos byp]# docker  pull redis:5.0.7
    5.0.7: Pulling from library/redis
    68ced04f60ab: Pull complete 
    7ecc253967df: Pull complete 
    765957bf98d4: Pull complete 
    52f16772e1ca: Pull complete 
    2e43ba99c3f3: Pull complete 
    d95576c71392: Pull complete 
    Digest: sha256:938ee5bfba605cc85f9f52ff95024e9a24cf5511ba6f1cbc68ec9d91a0432125
    Status: Downloaded newer image for redis:5.0.7
    docker.io/library/redis:5.0.7
    [root@VM-0-2-centos byp]# 
    

    创建挂载目录

    [root@VM-0-2-centos byp]# mkdir -p /home/app/redis/conf
    [root@VM-0-2-centos byp]# mkdir -p /home/app/redis/data
    [root@VM-0-2-centos byp]# 
    

    下载redis.conf

    https://redis.io/topics/config

    1.jpg
    进入目录并下载redis.conf
    注释符号 #
      1. 注释 bind 127.0.0.1  
      2. protected-mode yes 修改成 protected-mode no
      3. 添加 requirepass yourpassword (注:不添加则可以无密码访问)
      注:
         步骤1和步骤的2目的是为了远程连接redis,如果只需本地访问就无需修改
    

    创建启动容器

    [root@VM-0-2-centos conf]# docker run --restart=always  -d --privileged=true -p 6379:6379 -v /home/app/redis/conf/redis.conf:/etc/redis/redis.conf -v /home/app/redis/data:/data --name myRedis redis:5.0.7 redis-server /etc/redis/redis.conf --appendonly yes
    2514ca9103b468bb626252537ed4e5b01f15fa054ebb96b635d87fa543a021a1
    [root@VM-0-2-centos conf]# 
    

    参数解释

    --restart=always                                            -> 开机启动容器,容器异常自动重启
    -d                                                          -> 以守护进程的方式启动容器
    --privileged=true                                           -> 提升容器内权限
    -p 6379:6379                                                -> 绑定宿主机端口
    -v /home/app/redis/conf/redis.conf:/etc/redis/redis.conf    -> 映射配置文件
    -v /home/app/redis/data:/data                               -> 映射数据目录
    --name redis                                                -> 指定容器名称
    --appendonly yes                                            -> 开启数据持久化
    
    2.jpg

    参考链接

    https://www.cnblogs.com/roinbi/p/11972160.html

    下载运行redis

    [root@VM-0-2-centos ~]# docker run -p 6379:6379 -v $PWD/data:/data  -d redis:latest redis-server --appendonly yes
    af4ce8ae02f54435a3f5973f4e1aee12c81d9cd0c05526f13189653983906ecb
    [root@VM-0-2-centos ~]# docker ps -a
    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS                                NAMES
    af4ce8ae02f5        redis:latest        "docker-entrypoint.s…"   5 seconds ago       Up 4 seconds                0.0.0.0:6379->6379/tcp               mystifying_elgamal
    885d3be7e3be        redis:latest        "docker-entrypoint.s…"   12 minutes ago      Exited (1) 12 minutes ago                                        mystifying_kilby
    934fbb9c86fa        java-hello          "java -Djava.securit…"   4 hours ago         Up 4 hours                  0.0.0.0:80->80/tcp                   wonderful_zhukovsky
    13e442ccdff6        mysql               "docker-entrypoint.s…"   21 hours ago        Up 21 hours                 33060/tcp, 0.0.0.0:33060->3306/tcp   my-mysql
    [root@VM-0-2-centos ~]# 
    
    3.jpg

    相关文章

      网友评论

          本文标题:# Docker安装redis 5.0.7并挂载外部配置和数据

          本文链接:https://www.haomeiwen.com/subject/fnaaektx.html