首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何修复Docker Craft Cloud Run deployment中的“CloudSQL连接失败:超过上下文截止日期”

问如何修复Docker Craft Cloud Run deployment中的“CloudSQL连接失败:超过上下文截止日期”
EN

Stack Overflow用户
提问于 2019-08-08 16:03:10
回答 1查看 910关注 0票数 2

最近,当我尝试升级docker文件的php版本时,我开始收到CloudSQL连接错误。

日志示例。

代码语言:javascript
复制
2019-08-08T06:58:25.612096Z POST200 474 B 38 ms Chrome 75 /index.php?p=mangomin/actions/install/validate-db
2019-08-08T07:00:12.134410Z CloudSQL connection failed. Please see https://cloud.google.com/functions/docs/sql#troubleshooting for additional details: Post https://www.googleapis.com/sql/v1beta4/projects/c3gatsby-workflow-420fc457/instances/master-sql-f47f6b/createEphemeral?alt=json&prettyPrint=false: context deadline exceeded
2019-08-08T07:00:12.141939Z 169.254.8.129 - - [08/Aug/2019:07:00:02 +0000] "GET / HTTP/1.1" 503 52611 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36"
2019-08-08T07:00:12.144019Z GET503 51.4 KB 10 s Chrome 75 / 
2019-08-08T07:01:34.189448Z CloudSQL connection failed. Please see https://cloud.google.com/functions/docs/sql#troubleshooting for additional details: Post https://www.googleapis.com/sql/v1beta4/projects/c3gatsby-workflow-420fc457/instances/master-sql-f47f6b/createEphemeral?alt=json&prettyPrint=false: context deadline exceeded
2019-08-08T07:01:34.200976Z GET503 51.4 KB 10 s Chrome 75 / 

这开始于今天早上‘2019年8月8日’。起初,我以为我升级的php版本与unix socket或类似版本不兼容,所以我降级了。这不管用。所以我继续走回头路,回到昨天的版本(同样的env和docker sha)这个问题仍然存在,然后我回到了一个稳定的docker版本,我知道它正在做一个姊妹云运行服务。没有骰子。

简而言之,我试图更新的唯一一件事就是docker文件及其构建方式。(尝试启用opcache,我发现它在本地的工作很神奇,可以加速请求)旧的

代码语言:javascript
复制
FROM php:7.1-apache

# Enable Reqrite and Headers for .htaccess
RUN a2enmod rewrite
RUN a2enmod headers

# Ensure UTF-8
RUN echo "AddDefaultCharset UTF-8" > /var/www/html/.htaccess

# Install linux dependencies
RUN export CFLAGS="$PHP_CFLAGS" CPPFLAGS="$PHP_CPPFLAGS" LDFLAGS="$PHP_LDFLAGS" \
  && apt-get update --fix-missing \
  && apt-get install -y ssl-cert libmagickwand-dev libpq-dev zlib1g \
  && rm -rf /var/lib/apt/lists/*

# Install imagick
RUN pecl install imagick-3.4.3

# Install php extentions for docker
RUN docker-php-ext-enable imagick \
  && docker-php-ext-install pdo pdo_mysql zip

# Enable SSL apache2
RUN a2ensite default-ssl \
  && a2enmod ssl

# Replace the default served file to /web
RUN sed -i 's%/var/www/html%/var/www/html/web%g' /etc/apache2/sites-enabled/*.conf

# Use the PORT environment variable in Apache configuration files.
RUN sed -i 's/80/${PORT}/g' /etc/apache2/sites-enabled/000-default.conf /etc/apache2/ports.conf

# Replace with production mode
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

# Up the upload file size limit, memory limit and max-execution time
RUN sed -i "s/max_input_time = 30/max_input_time = 120/g" "$PHP_INI_DIR/php.ini"
RUN sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 5M/g" "$PHP_INI_DIR/php.ini"
RUN sed -i "s/max_execution_time = 30/max_execution_time = 120/g" "$PHP_INI_DIR/php.ini"
RUN sed -i "s/memory_limit = 128M/memory_limit = 256M/g" "$PHP_INI_DIR/php.ini"

新的

代码语言:javascript
复制
FROM php:7.3-apache-stretch

# Enable Reqrite and Headers for .htaccess
RUN a2enmod rewrite
RUN a2enmod headers

# Ensure UTF-8
RUN echo "AddDefaultCharset UTF-8" > /var/www/html/.htaccess

RUN export CFLAGS="$PHP_CFLAGS" CPPFLAGS="$PHP_CPPFLAGS" LDFLAGS="$PHP_LDFLAGS"

# Install linux dependencies
RUN apt-get update --fix-missing \
  && apt-get install -y libfreetype6-dev libjpeg62-turbo-dev \
  libpng-dev libbz2-dev \
  libssl-dev autoconf \
  ca-certificates curl g++ libicu-dev mysql-client \
  ssl-cert libmagickwand-dev libpq-dev zlib1g libzip-dev \
  && rm -rf /var/lib/apt/lists/*

# Install imagick
RUN pecl install imagick-3.4.3

# Install php extentions for docker
RUN docker-php-ext-enable imagick

RUN docker-php-ext-install bcmath bz2 exif \
  gd gettext mbstring opcache

RUN docker-php-ext-install shmop sockets sysvmsg sysvsem sysvshm \
  zip iconv pdo_mysql intl

# Enable SSL apache2
RUN a2ensite default-ssl \
  && a2enmod ssl

COPY php/opcache.ini /usr/local/etc/php/conf.d/opcache.ini

ENV PHP_OPCACHE_VALIDATE_TIMESTAMPS="0" \
  PHP_OPCACHE_MAX_ACCELERATED_FILES="10000" \
  PHP_OPCACHE_MEMORY_CONSUMPTION="192" \
  PHP_OPCACHE_MAX_WASTED_PERCENTAGE="10"

# Replace the default served file to /web
RUN sed -i 's%/var/www/html%/var/www/html/web%g' /etc/apache2/sites-enabled/*.conf

# Use the PORT environment variable in Apache configuration files.
RUN sed -i 's/80/${PORT}/g' /etc/apache2/sites-enabled/000-default.conf /etc/apache2/ports.conf

# Replace with production mode
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

# Up the upload file size limit, memory limit and max-execution time
RUN sed -i "s/max_input_time = 30/max_input_time = 120/g" "$PHP_INI_DIR/php.ini" && \
  sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 10M/g" "$PHP_INI_DIR/php.ini" && \
  sed -i "s/max_execution_time = 30/max_execution_time = 120/g" "$PHP_INI_DIR/php.ini" && \
  sed -i "s/memory_limit = 128M/memory_limit = 512M/g" "$PHP_INI_DIR/php.ini"

我为张贴整个文件道歉。

预期的和实际的结果已经解释过了。

我发现的一些观察结果是,超时恰好是10秒,如果这与什么有关的话。

任何帮助都将不胜感激。

提前谢谢你。

EN

回答 1

Stack Overflow用户

发布于 2019-09-27 20:09:52

检查并确保您的云SQL实例已开启公网IP连接。未开启时,云SQL proxy将无法正常工作。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57407906

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档