• Docker下安装redis


    先去搜索镜像

    [root@localhost admin]# docker search redis
    INDEX       NAME                                       DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
    docker.io   docker.io/redis                            Redis is an open source key-value store th...   7267      [OK]       
    docker.io   docker.io/bitnami/redis                    Bitnami Redis Docker Image                      125                  [OK]
    docker.io   docker.io/sameersbn/redis                                                                  77                   [OK]
    docker.io   docker.io/grokzen/redis-cluster            Redis cluster 3.0, 3.2, 4.0 & 5.0               55                   
    docker.io   docker.io/rediscommander/redis-commander   Alpine image for redis-commander - Redis m...   30                   [OK]
    docker.io   docker.io/kubeguide/redis-master           redis-master with "Hello World!"                29                   
    docker.io   docker.io/redislabs/redis                  Clustered in-memory database engine compat...   23                   
    docker.io   docker.io/arm32v7/redis                    Redis is an open source key-value store th...   17                   
    docker.io   docker.io/redislabs/redisearch             Redis With the RedisSearch module pre-load...   17                   
    docker.io   docker.io/oliver006/redis_exporter          Prometheus Exporter for Redis Metrics. Su...   14                   
    docker.io   docker.io/s7anley/redis-sentinel-docker    Redis Sentinel                                  10                   [OK]
    docker.io   docker.io/webhippie/redis                  Docker images for Redis                         10                   [OK]
    docker.io   docker.io/bitnami/redis-sentinel           Bitnami Docker Image for Redis Sentinel         7                    [OK]
    docker.io   docker.io/insready/redis-stat              Docker image for the real-time Redis monit...   7                    [OK]
    docker.io   docker.io/redislabs/redisgraph             A graph database module for Redis               7                    [OK]
    docker.io   docker.io/arm64v8/redis                    Redis is an open source key-value store th...   6                    
    docker.io   docker.io/centos/redis-32-centos7          Redis in-memory data structure store, used...   4                    
    docker.io   docker.io/redislabs/redismod               An automated build of redismod - latest Re...   4                    [OK]
    docker.io   docker.io/circleci/redis                   CircleCI images for Redis                       2                    [OK]
    docker.io   docker.io/frodenas/redis                   A Docker Image for Redis                        2                    [OK]
    docker.io   docker.io/runnable/redis-stunnel           stunnel to redis provided by linking conta...   1                    [OK]
    docker.io   docker.io/tiredofit/redis                  Redis Server w/ Zabbix monitoring and S6 O...   1                    [OK]
    docker.io   docker.io/wodby/redis                      Redis container image with orchestration        1                    [OK]
    docker.io   docker.io/cflondonservices/redis           Docker image for running redis                  0                    
    docker.io   docker.io/xetamus/redis-resource           forked redis-resource                           0                    [OK]

    下载

    [root@localhost admin]# docker pull redis
    Using default tag: latest
    Trying to pull repository docker.io/library/redis ... 
    latest: Pulling from docker.io/library/redis
    1ab2bdfe9778: Already exists 
    966bc436cc8b: Pull complete 
    c1b01f4f76d9: Pull complete 
    8a9a85c968a2: Pull complete 
    8e4f9890211f: Pull complete 
    93e8c2071125: Pull complete 
    Digest: sha256:9755880356c4ced4ff7745bafe620f0b63dd17747caedba72504ef7bac882089
    Status: Downloaded newer image for docker.io/redis:latest

    查看镜像信息

    [root@localhost admin]# docker images
    REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
    docker.io/redis               latest              f7302e4ab3a8        2 weeks ago         98.2 MB
    [root@localhost admin]# docker inspect f7302e4ab3a8
    ...
                "Env": [
                    "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                    "GOSU_VERSION=1.11",
                    "REDIS_VERSION=5.0.5",
                    "REDIS_DOWNLOAD_URL=http://download.redis.io/releases/redis-5.0.5.tar.gz",
                    "REDIS_DOWNLOAD_SHA=2139009799d21d8ff94fc40b7f36ac46699b9e1254086299f8d3b223ca54a375"
                ],
                "Cmd": [
                    "/bin/sh",
                    "-c",
                    "#(nop) ",
                    "CMD ["redis-server"]"
                ],
                "ArgsEscaped": true,
                "Image": "sha256:389cabb829aa5d33a92313baa7153be1d5b14717fba178d24083ee5d7051c822",
                "Volumes": {
                    "/data": {}
                },
                "WorkingDir": "/data",
                "Entrypoint": [
                    "docker-entrypoint.sh"
                ],
                "OnBuild": null,
                "Labels": {}
            },
            "DockerVersion": "18.06.1-ce",
    ...
                "ExposedPorts": {
                    "6379/tcp": {}
                },
    ...
                "Cmd": [
                    "redis-server"
                ],
    ...

    可以看到,版本是5.0.5,数据目录是/data,端口是6379。

    下面创建容器

    [root@localhost admin]# docker run --name some-redis -p 6379:6379 -d --privileged -v /usr/local/redis_data:/data redis redis-server --appendonly yes
    ff3ddf85b4a92958c416ad33dbd0553485639ca48c057966290c35f7687a2435
    [root@localhost admin]# docker ps
    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
    ff3ddf85b4a9        redis               "docker-entrypoint..."   10 seconds ago      Up 9 seconds        0.0.0.0:6379->6379/tcp   some-redis
    [root@localhost admin]# docker logs -f some-redis
    1:C 30 Aug 2019 06:47:31.650 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
    1:C 30 Aug 2019 06:47:31.650 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=1, just started
    1:C 30 Aug 2019 06:47:31.650 # Configuration loaded
    1:M 30 Aug 2019 06:47:31.652 * Running mode=standalone, port=6379.
    1:M 30 Aug 2019 06:47:31.652 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
    1:M 30 Aug 2019 06:47:31.652 # Server initialized
    1:M 30 Aug 2019 06:47:31.652 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
    1:M 30 Aug 2019 06:47:31.652 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
    1:M 30 Aug 2019 06:47:31.652 * Ready to accept connections

    创建并启动成功。

    参数解释:

    docker run --name some-redis -p 6379:6379 -d --privileged -v /usr/local/redis_data:/data redis redis-server --appendonly yes
    
    --name:容器命名
    -p:宿主机端口:容器内端口
    -d:后台启动
    --privileged:【chown: changing ownership of '.': Permission denied】授权
    -v:将容器内的目录挂载到宿主机目录
    redis:镜像名称
    redis-server --appendonly yes:容器内执行redis-server命令,并打开持久化
    

      

    在本地用redis客户端连接容器redis:

    redis-cli.exe -h 192.168.192.128 -p 6379

     简单测一下:

    然后回到容器,看一下有没有

  • 相关阅读:
    硬盘分区、寻址和系统启动过程
    剑指offer---05---用栈实现队列
    剑指offer---05---用栈实现队列
    服务端提供的JSON数据接口与用户端接收解析JSON数据
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
  • 原文地址:https://www.cnblogs.com/LUA123/p/11435000.html
Copyright © 2020-2023  润新知