docker 安装 redis

2 阅读1分钟

下面的安装环境:Centos7 + docker

下载镜像

docker pull redis

安装

  • 创建主目录

    mkdir -p /usr/local/redis
    cd /usr/local/redis
    mkdir -p data conf
    
  • 创建配置文件:将配置文件 redis.conf 保存到 /usr/local/redis/conf 目录,内容如下

    # 所有主机都可以连接
    bind 0.0.0.0
    # 关闭保护模式
    protected-mode no
    # 端口号
    port 6379
    # 密码
    requirepass 123456
    always-show-logo yes
    
  • 安装数据库

    docker run --name redis --restart=always -p 6379:6379 -d redis
    

登录测试

  • 创建终端

    
    docker exec -it redis /bin/bash
    root@afeb53a49bdf:/data#
    
  • 登录并测试

    
    root@afeb53a49bdf:/data# redis-cli -a 123456
    Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
    127.0.0.1:6379> set test master
    OK
    127.0.0.1:6379> get test
    "master"