我想在云运行应用程序中连接Cloud。我用过金刚。这是围绕设置的代码。
func getEnv(key, def string) string {
v := os.Getenv(key)
if v == "" {
return def
}
return v
} DB: DB{
User: getEnv("DB_USER", "<user name>"),
Pass: getEnv("DB_PASS", "<password>"),
Host: getEnv("DB_HOST", "0.0.0.0"),
Port: getEnv("DB_PORT", "3306"),
Database: getEnv("DB_DATABASE", "<database name>"),
}, dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8&parseTime=true",
config.DB.User, config.DB.Pass, config.DB.Host, config.DB.Port, config.DB.Database)
db, err := gorm.Open("mysql", dsn)我在云运行设置控制台设置了环境变量。在delpoy应用程序之后,云运行控制台显示Cloud Run error: Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable. Logs for this revision might contain more information.和dial tcp <Cloud SQL Private IP> :3306: connect: connection timed out我怀疑SQL连接是错误的.
发布于 2020-07-15 01:38:34
你没有在你的问题中提到"VPC“这个词,所以我假设你没有使用它。
云运行不能直接连接到Cloud实例的私有IP。您需要在部署云运行应用程序时指定配置无服务器的VPC访问连接器并指定它。
默认情况下,云运行容器并不是VPC的一部分,因此除非您这样做,否则它们将无法访问专用网络。
发布于 2020-07-15 08:26:17
有几种方法可以将Cloud数据库连接到云运行。如果是MySQL,最简单的方法就是遵循正式文件
如果您想使用带有TCP连接的IP,首先,不能使用0.0.0.0作为IP。
https://stackoverflow.com/questions/62905897
复制相似问题