无法从Docker容器连接到Aurora MySQL,但使用命令行工作

时间:2018-07-18 23:49:20

标签: docker go amazon-rds aurora

am尝试从ec2实例执行此操作,尝试连接到AWS RDS Aurora mysql。以下命令可让我连接到rds: mysql -h cluster.cluster-c3dpvouhxmjg.us-east-1.rds.amazonaws.com --port 3306 -u root -p

我编写了一个golang应用程序,并在此处使用docker将其容器化: Dockerfile:

FROM artifactory.cloud.com/research/golang:1.10-alpine3.7

RUN mkdir -p /go/src/github.com/perfGo/
WORKDIR /go/src/github.com/perfGo
COPY ./ $WORKDIR
RUN apk update && apk upgrade
RUN go build

RUN chmod +x ./entrypoint.sh
RUN ls
RUN chmod +x ./perfGo
EXPOSE 3306
#I set the proxies here

ENTRYPOINT ["./entrypoint.sh"]

entrypoint.sh

#!/usr/bin/env bash
./perfGo

perf.go

package main

import (
    "database/sql"
 _ "github.com/go-sql-driver/mysql"
)

func main() {
    db, err := sql.Open("mysql", "root:fdsffdsfs@tcp(cluster.cluster-c3dpvouhxmjg.us-east-1.rds.amazonaws.com:3306)/testdb")
    checkErr(err)
    _,dbErr := db.Exec("USE testdb")
    if err != nil {
        panic(dbErr)
    }

    // insert
    _, inErr := db.Query("INSERT INTO books VALUES('tttt','dsfdsfs','fdsfasaf','55')")

    defer db.Close()
    // if there is an error inserting, handle it
    if inErr != nil {
        panic(inErr.Error())
    }

}

func checkErr(err error) {
    if err != nil {
        panic(err)
    }
}

我用来运行容器的命令是

docker run -p 3306:3306 -ti 23b3c5c510b4

我看到的错误是: 紧急:拨打tcp:查找cluster.cluster-c3dpvouhxmjg.us-east-1.rds.amazonaws.com on 8.8.4.4:53:读udp 172.17.0.2:52640->8.8.4.4:53:I / O超时 有人可以帮我这个忙吗?这完全可以在我的Mac上使用localhost上的mysql的容器上工作

0 个答案:

没有答案