docker安装部署redis用docker-compose启动设置密码(Docker installation and deployment redis starts with docker compose and sets the password)

搜索镜像

[root@localhost ~]# docker search redisNAME                             DESCRIPTION                                     STARS     OFFICIAL   AUTOMATEDredis                            Redis is an open source key-value store that…   10202     [OK]       sameersbn/redis                                                                  83                   [OK]grokzen/redis-cluster            Redis cluster 3.0, 3.2, 4.0, 5.0, 6.0, 6.2      80                   rediscommander/redis-commander   Alpine image for redis-commander – Redis man…   70                   [OK]redislabs/redisearch             Redis With the RedisSearch module pre-loaded…   41                   redislabs/redisinsight           RedisInsight – The GUI for Redis                35                   kubeguide/redis-master           redis-master with “Hello World!”                33                   oliver006/redis_exporter          Prometheus Exporter for Redis Metrics. Supp…   31                   redislabs/redis                  Clustered in-memory database engine compatib…   31                   redislabs/rejson                 RedisJSON – Enhanced JSON data type processi…   31                   arm32v7/redis                    Redis is an open source key-value store that…   25                   arm64v8/redis                    Redis is an open source key-value store that…   19                   redislabs/redisgraph             A graph database module for Redis               17                   [OK]redislabs/rebloom                A probablistic datatypes module for Redis       16                   [OK]redislabs/redismod               An automated build of redismod – latest Redi…   15                   [OK]webhippie/redis                  Docker image for redis                          11                   [OK]s7anley/redis-sentinel-docker    Redis Sentinel                                  10                   [OK]insready/redis-stat              Docker image for the real-time Redis monitor…   10                   [OK]redislabs/redistimeseries        A time series database module for Redis         10                   goodsmileduck/redis-cli          redis-cli on alpine                             9                    [OK]centos/redis-32-centos7          Redis in-memory data structure store, used a…   6                    clearlinux/redis                 Redis key-value data structure server with t…   3                    tiredofit/redis                  Redis Server w/ Zabbix monitoring and S6 Ove…   1                    [OK]wodby/redis                      Redis container image with orchestration        1                    [OK]xetamus/redis-resource           forked redis-resource                           0                    [OK]

拉取镜像

[root@localhost ~]# docker pull redisUsing default tag: latestlatest: Pulling from library/rediseff15d958d66: Pull complete 1aca8391092b: Pull complete 06e460b3ba1b: Pull complete def49df025c0: Pull complete 646c72a19e83: Pull complete db2c789841df: Pull complete Digest: sha256:619af14d3a95c30759a1978da1b2ce375504f1af70ff9eea2a8e35febc45d747Status: Downloaded newer image for redis:latestdocker.io/library/redis:latest

设置docker-compose.yml配置

[root@localhost bin]# vi docker-compose.yml

version: ‘3’services:  redis:    image: redis:latest    restart: always    container_name: redis    command:      – /bin/bash      – -c      – redis-server /usr/local/bin/redis.conf/redis.conf –requirepass “xxxxxxxx”    privileged: true    ports:      – “0.0.0.0:6379:6379”    volumes:      – ./redis/data:/data      – ./redis/redis.conf:/usr/local/bin/redis.conf/redis.conf

创建Redis容器

[root@localhost bin]# docker-compose up -d

Creating redis         … done[root@localhost bin]# docker ps -aCONTAINER ID    IMAGE                       COMMAND                    CREATED              STATUS              PORTS                                           NAMESe558e25c45bb     redis:latest                “docker-entrypoint.s…”    13 minutes ago     Up 13 minutes     0.0.0.0:6379->6379/tcp                    redis

本机客户端登录

root@e558e25c45bb:/usr/local/bin# root@e558e25c45bb:/usr/local/bin# ./redis-cli -h 127.0.0.1 -p 6379 -a “xxxxxx”Warning: Using a password with ‘-a’ or ‘-u’ option on the command line interface may not be safe.127.0.0.1:6379> pingPONG127.0.0.1:6379>

————————

Search image

[ root@localhost ~]# docker search redisNAME                              DESCRIPTION                                      STARS      OFFICIAL    AUTOMATEDredis                             Redis is an open source key-value store that…    ten thousand two hundred and two      [OK]         sameersbn/redis                                                                   eighty-three                    [OK]grokzen/redis-cluster             Redis cluster 3.0, 3.2, 4.0, 5.0, 6.0, 6.2       eighty                     rediscommander/redis-commander    Alpine image for redis-commander – Redis man…    seventy                    [OK]redislabs/redisearch              Redis With the RedisSearch module pre-loaded…    forty-one                     redislabs/redisinsight            RedisInsight – The GUI for Redis                 thirty-five                     kubeguide/redis-master            redis-master with “Hello World!”                 thirty-three                     oliver006/redis_ exporter           Prometheus Exporter for Redis Metrics. Supp…    thirty-one                     redislabs/redis                   Clustered in-memory database engine compatib…    thirty-one                     redislabs/rejson                  RedisJSON – Enhanced JSON data type processi…    thirty-one                     arm32v7/redis                     Redis is an open source key-value store that…    twenty-five                     arm64v8/redis                     Redis is an open source key-value store that…    nineteen                     redislabs/redisgraph              A graph database module for Redis                seventeen                    [OK]redislabs/rebloom                 A probablistic datatypes module for Redis        sixteen                    [OK]redislabs/redismod                An automated build of redismod – latest Redi…    fifteen                    [OK]webhippie/redis                   Docker image for redis                           eleven                    [OK]s7anley/redis-sentinel-docker     Redis Sentinel                                   ten                    [OK]insready/redis-stat               Docker image for the real-time Redis monitor…    ten                    [OK]redislabs/redistimeseries         A time series database module for Redis          ten                     goodsmileduck/redis-cli           redis-cli on alpine                              nine                     [OK]centos/redis-32-centos7           Redis in-memory data structure store, used a…    six                      clearlinux/redis                  Redis key-value data structure server with t…    three                      tiredofit/redis                   Redis Server w/ Zabbix monitoring and S6 Ove…    one                     [OK]wodby/redis                       Redis container image with orchestration         one                     [OK]xetamus/redis-resource            forked redis-resource                            0                     [OK]

Pull image

[root@localhost ~]# docker pull redisUsing default tag: latestlatest: Pulling from library/rediseff15d958d66: Pull complete 1aca8391092b: Pull complete 06e460b3ba1b: Pull complete def49df025c0: Pull complete 646c72a19e83: Pull complete db2c789841df: Pull complete Digest: sha256:619af14d3a95c30759a1978da1b2ce375504f1af70ff9eea2a8e35febc45d747Status: Downloaded newer image for redis:latestdocker.io/library/redis:latest

设置docker-compose.yml配置

[root@localhost bin]# vi docker-compose.yml

version: ‘3’services:  redis:    image: redis:latest    restart: always    container_name: redis    command:      – /bin/bash      – -c      – redis-server /usr/local/bin/redis.conf/redis.conf –requirepass “xxxxxxxx”    privileged: true    ports:      – “0.0.0.0:6379:6379”    volumes:      – ./redis/data:/data      – ./redis/redis.conf:/usr/local/bin/redis.conf/redis.conf

创建Redis容器

[root@localhost bin]# docker-compose up -d

Creating redis          … done[ root@localhost bin]# docker ps -aCONTAINER ID     IMAGE                        COMMAND                     CREATED               STATUS               PORTS                                            NAMESe558e25c45bb      redis:latest                 “docker-entrypoint.s…”     13 minutes ago      Up 13 minutes      0.0.0.0:6379-> 6379/tcp                     redis

Native Client Login

root@e558e25c45bb:/usr/local/bin# root@e558e25c45bb:/usr/local/bin# ./redis-cli -h 127.0.0.1 -p 6379 -a “xxxxxx”Warning: Using a password with ‘-a’ or ‘-u’ option on the command line interface may not be safe.127.0.0.1:6379> pingPONG127.0.0.1:6379>