使用TCP从App Engine自定义环境连接到Google Cloud SQL时出错 [英] Error connecting to Google Cloud SQL from App Engine custom environment using TCP

查看:87
本文介绍了使用TCP从App Engine自定义环境连接到Google Cloud SQL时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从App Engine中的自定义运行时环境连接到Google sql云实例.

当我遵循 doc 时,使用UNIX进行连接域套接字,它的工作原理.问题是当我尝试使用TCP连接进行连接时.它显示:

Warning: mysqli_connect(): (HY000/2002): Connection refused in 
/var/www/html/index.php on line 3
Connect error: Connection refused

这是我的app.yaml文件:

runtime: custom
env: flex

beta_settings:
  cloud_sql_instances: testing-mvalcam:europe-west1:testdb=tcp:3306

resources:
  cpu: 1
  memory_gb: 0.5
  disk_size_gb: 10

Dockerfile:

FROM php:7.0-apache

ENV PORT 8080
CMD sed -i "s/80/$PORT/g" /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf && docker-php-entrypoint apache2-foreground

RUN docker-php-ext-install mysqli
RUN a2enmod rewrite

COPY ./src /var/www/html

EXPOSE $PORT

还有index.php:

<?php

$link = mysqli_connect('127.0.0.1', 'root', 'root', 'test');

if (!$link){
    die('Connect error: '. mysqli_connect_error());
}

echo 'successfully connected';
mysqli_close($link);

?>

我在做什么错了?

解决方案

IP地址"172.17.0.1"与Web服务器运行所在的Docker容器相关,您可以在文档中,您可以阅读有关App Engine灵活运行时的更多信息. >

I'm trying to connect to google sql cloud instance from custom runtime environment in App Engine.

When I follow the doc to connect using unix domain socket, it works. The problem is when I try to connect using a TCP connect. It shows:

Warning: mysqli_connect(): (HY000/2002): Connection refused in 
/var/www/html/index.php on line 3
Connect error: Connection refused

This is my app.yaml file:

runtime: custom
env: flex

beta_settings:
  cloud_sql_instances: testing-mvalcam:europe-west1:testdb=tcp:3306

resources:
  cpu: 1
  memory_gb: 0.5
  disk_size_gb: 10

The Dockerfile:

FROM php:7.0-apache

ENV PORT 8080
CMD sed -i "s/80/$PORT/g" /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf && docker-php-entrypoint apache2-foreground

RUN docker-php-ext-install mysqli
RUN a2enmod rewrite

COPY ./src /var/www/html

EXPOSE $PORT

And index.php:

<?php

$link = mysqli_connect('127.0.0.1', 'root', 'root', 'test');

if (!$link){
    die('Connect error: '. mysqli_connect_error());
}

echo 'successfully connected';
mysqli_close($link);

?>

What am I doing Wrong?

解决方案

The ip address ‘172.17.0.1’ is related with the docker container where the webserver is running, you can get more context on that in this documentation.

The documentation page you’re using might be lacking on adjusting the use case if you’re deploying with a presence of a Dockerfile. In the following documentation you can read more information about App Engine flexible runtimes.

这篇关于使用TCP从App Engine自定义环境连接到Google Cloud SQL时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆