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 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?