dongle2627
2019-08-15 19:27
浏览 592

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

相关推荐 更多相似问题