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

容器将无法连接到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条)

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器