dping1968 2018-07-18 23:49
浏览 90

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

am trying to do this from an ec2 instance, trying to connect to aws rds aurora mysql. The following command lets me connect to the rds: mysql -h cluster.cluster-c3dpvouhxmjg.us-east-1.rds.amazonaws.com --port 3306 -u root -p

I have written a golang application and containerized it using docker here: 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)
    }
}

The command I use to run the contianer is

docker run -p 3306:3306 -ti 23b3c5c510b4

The error I see is : panic: dial tcp: lookup cluster.cluster-c3dpvouhxmjg.us-east-1.rds.amazonaws.com on 8.8.4.4:53: read udp 172.17.0.2:52640->8.8.4.4:53: i/o timeout Can someone pls help me out on this. This totally works on container on my mac using mysql on localhost

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探
    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
    • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
    • ¥15 可见光定位matlab仿真
    • ¥15 arduino 四自由度机械臂
    • ¥15 wordpress 产品图片 GIF 没法显示