doudu161481
2017-03-27 06:42
采纳率: 100%
浏览 1.7k

尝试使用docker compose文件连接Redis时连接被拒绝

我在尝试使用redis-golang驱动程序连接到Redis时遇到问题。 这是我的 docker-compose.yml文件 :

version: "3"

services:
  driver:
    build: ./API-Golang
    command: go run app.go
    volumes:
     - ./API-Golang:/app
    ports:
      - "8080:8080"
    depends_on:
      - db
      - redis
    links :
      - redis
      - db
  redis:
    image: redis
    container_name: redis
    ports: ["6379:6379"]
  db:
    image: mongo:3.4.2
    container_name: mongodb
    ports : ["27017:27017"]

这是我试图连接到redis (API-Golang/数据库/allSystem.go)的代码:

redisConn := RedisHost{
    Address:  "localhost:6379",
    Password: "",
    DB:       0,
}

redisConnection, err := redisConn.Connect()
if err != nil {
    panic(err)
}

我试图改变 localhostredis 但它还是不管用。错误如下:

driver_1  | panic: dial tcp [::1]:6379: getsockopt: connection refused
driver_1  | 
driver_1  | goroutine 1 [running]:
driver_1  | github.com/Gujarats/API-Golang/database.SystemConnection(0x48)
driver_1  |     /go/src/github.com/Gujarats/API-Golang/database/allSystem.go:32 +0x3d3
driver_1  | main.main()
driver_1  |     /go/src/github.com/Gujarats/API-Golang/app.go:24 +0x34
driver_1  | exit status 2

你知道哪里出错了吗?

源代码

2条回答 默认 最新

相关推荐 更多相似问题