dongle2627 2019-08-15 19:27
浏览 601
已采纳

容器将无法连接到Redis容器

I'm trying to connect to my redis container from my container running a Go server but the the connection keeps getting refused despite what appears to be a correct setup in my docker-compose.yml:

Go

redisClient = redis.NewClient(&redis.Options{
        Network:  "tcp",
        Addr:     "redis_server:6379",
        Password: "", // no password set
        DB:       0,  // use default DB
    })

docker-compose

version: "0.1"
services:
  redis_server:
    image: "redis"
    ports:
      - "6379:6379"
  lambda_server:
    build: .
    ports:
      - "8080:50051"
    links:
      - redis_server
  • 写回答

2条回答 默认 最新

  • dongzongzi0379 2019-08-15 19:36
    关注

    By default, Redis doesn’t allow remote connections. You can connect to the Redis server only from 127.0.0.1 (localhost) - the machine where Redis is running.

    Replace bind 127.0.0.1 with bind 0.0.0.0 in the /etc/redis/redis.conf file.

    then run sudo service redis-server restart to restart the server.

    Use the following command to verify that redis is listening on all interfaces on port 6379:

    ss -an | grep 6379
    

    You should see something like below. 0.0.0.0 means all IPv4 addresses on the machine.

    tcp  LISTEN 0   128   0.0.0.0:6379   0.0.0.0:*
    tcp  LISTEN 0   128      [::]:6379      [::]:* 
    

    If that doesn't solve the problem, you might need to check any firewalls that might block the access.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据