【问题标题】:RedisInsight on Docker and Redis on Docker: Could not connect: Error 99 connecting to localhost:6379. Cannot assign requested addressDocker 上的 RedisInsight 和 Docker 上的 Redis:无法连接:连接到 localhost:6379 时出现错误 99。无法分配请求的地址
【发布时间】:2020-10-10 15:43:37
【问题描述】:

根据本教程https://www.youtube.com/watch?v=XrFeRwJjWHI,我尝试在 Docker 中运行 Redis。

文件docker-compose.yml

version: "3.8"

services:
  redis:
    image: redis
    volumes:
      - ./data:/data
    ports:
      - 6379:6379
docker pull redis
docker-compose up
docker-compose up -d
docker container ls
telnet localhost 6379

Telnet,输入PING,然后按回车键(你不会看到文本),然后看到结果:PONG。输入quit 退出。

Microsoft Windows [Version 10.0.19041.508]
(c) 2020 Microsoft Corporation. All rights reserved.

D:\docker>docker-compose stop redis
Stopping docker_redis_1 ... done

D:\docker>

查看正在运行的内容

docker container ls

你会看到,docker redis 已经停止了。

docker image prune -a
docker-compose up

Docker RedisInsight

docker run -v redisinsight:/db -p 8001:8001 redislabs/redisinsight:latest

等待大约 6 分钟(以 22:30 的互联网速度)下载、解压缩、安装、启动。

转到:http://localhost:8001/(自动打开网络浏览器)。 RedisInsight http://localhost:8001/healthcheck/ 的健康检查正常。

(我也注意到这里https://donhuvy.github.io/redis/docker/2020/10/10/run-redis-on-docker.html

如何正确连接RedisInsight和Redis?

更新:这是我的主机文件,这里似乎有问题(Kubernetes 的 IP 127.0.0.1,我真的不了解 Kubernetes,我正在学习它。),但我不知道如何解决。

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
#   127.0.0.1       localhost
#   ::1             localhost

127.0.0.1    www.techsmith.com
127.0.0.1    activation.cloud.techsmith.com
127.0.0.1    oscount.techsmith.com
127.0.0.1    updater.techsmith.com
127.0.0.1    camtasiatudi.techsmith.com
127.0.0.1    tsccloud.cloudapp.net
127.0.0.1    assets.cloud.techsmith.com

# Added by Docker Desktop
192.168.1.44 host.docker.internal
192.168.1.44 gateway.docker.internal
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section

【问题讨论】:

  • 这些容器是否在同一个网络中运行?尝试列出网络和容器,看看它们是否在同一个网络上
  • 如何列出网络和容器?
  • 你得到答案了吗?
  • 我不确定。
  • 您可以执行以下操作以使用 docker 列出网络:docker network ls。要检查容器的网络,您可以执行以下操作:$ docker inspect c1 -f "{{json .NetworkSettings.Networks }}" c1 == 容器的名称。

标签: docker redis docker-compose docker-container redisinsights


【解决方案1】:

docker-compose.yml 中使用此设置

version: '3.7'

services:
  redis:
    image: 'redis:6.0.6'
    ports:
      - '127.0.0.1:6379:6379/tcp'
    volumes:
      - 'redis_data:/data:rw'
    healthcheck:
      test: redis-cli ping
      interval: 3s
      timeout: 5s
      retries: 5

  redisinsight:
    image: 'redislabs/redisinsight:latest'
    ports:
      - '127.0.0.1:8001:8001'

你可以通过

访问redis

【讨论】:

    【解决方案2】:

    RedisInsight 正在尝试连接到容器的本地主机。尝试在Host 字段中输入127.0.0.1

    如果文件主机已更改,如相关更新信息,请使用192.168.1.44

    【讨论】:

    【解决方案3】:

    由于您没有提到容器的任何网络,因此它们连接到 默认网桥 网络。 learn more

    获取容器IP地址

    输入你的终端

    # Check container network IP address
    
    docker container inspect -f "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" <container name>
    
    

    使用 IP 地址:http://localhost:8001/ (RedisInsight)。

    (不推荐)输入您的主机的IP address将解决问题

    根据您的操作系统使用ipconfigifconfig 获取您的IP

    【讨论】:

      【解决方案4】:

      为了让您的容器能够相互访问,您应该首先将它们连接到同一个网络。

      docker network create redis
      docker network connect redis elastic_diffie
      docker network connect redis docker_redis_1
      

      然后打开 RedisInsight UI 并将docker_redis_1 写入您的主机并保持端口相同。您应该能够连接到您的 redis 容器。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-09-19
        • 2021-12-17
        • 2020-03-13
        • 2021-06-01
        • 1970-01-01
        • 2011-06-07
        • 2020-05-20
        相关资源
        最近更新 更多