简体   繁体   中英

Cloud Run service in GCP shows “Container failed to start and then listen on the port defined by the PORT environment variable” Codeigniter 4

I am trying continuous deployment of codeigniter 4 application from github repo using cloud build in GCP, but it shows failed to listen port but I used port environment variable, Help me with this error

My Docker File

FROM php:fpm

RUN ["apt-get", "update"]
RUN ["apt-get", "install", "-y", "libzip-dev"]
RUN ["apt-get", "install", "-y", "zip"]
RUN ["apt-get", "install", "-y", "unzip"]
RUN ["apt-get", "install", "-y", "libxml2-dev"]
RUN ["docker-php-ext-install", "soap"]
RUN ["docker-php-ext-configure", "zip"]
RUN ["docker-php-ext-install", "mysqli", "pdo", "pdo_mysql", "zip"]

RUN touch /usr/local/etc/php/conf.d/uploads.ini \
    && echo "upload_max_filesize=64M;\r\n post_max_size=128M;\r\nmemory_limit = 512M" >> /usr/local/etc/php/conf.d/uploads.ini

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

COPY ./writable /var/www/html/writable

## Install codeIgniter Dependecies
COPY ./composer.json /var/www/html/composer.json
RUN cd /var/www/html/ && composer update /var/www/html/ --no-dev --ignore-platform-reqs "vendor/*"

RUN cd /var/www/html/
#RUN ["chmod", "-R", "777", "writable/"]
RUN ["chown", "-R", "www-data:www-data", "/var/www/html/"]
########################################

EXPOSE ${PORT}

My composer.json file

{
  "name": "codeigniter4/appstarter",
  "type": "project",
  "description": "CodeIgniter4 starter app",
  "homepage": "https://codeigniter.com",
  "license": "MIT",
  "require": {
    "php": ">=7.2",
    "codeigniter4/framework": "^4"
  },
  "require-dev": {
    "mikey179/vfsstream": "1.6.*",
    "phpunit/phpunit": "8.5.*"
  },
  "autoload-dev": {
    "psr-4": {
      "Tests\\Support\\": "tests/_support"
    }
  },
  "scripts": {
    "test": "phpunit",
    "post-update-cmd": [
      "@composer dump-autoload"
    ]
  },
  "support": {
    "forum": "http://forum.codeigniter.com/",
    "source": "https://github.com/codeigniter4/CodeIgniter4",
    "slack": "https://codeigniterchat.slack.com"
  }
}
FROM php:7.3-apache

RUN apt-get update
RUN apt-get upgrade -y

RUN apt-get install --fix-missing -y libpq-dev
RUN apt-get install --no-install-recommends -y libpq-dev
RUN apt-get install -y libxml2-dev libbz2-dev zlib1g-dev
RUN apt-get -y install libsqlite3-dev libsqlite3-0 mariadb-client curl exif ftp
RUN docker-php-ext-install intl
RUN apt-get -y install --fix-missing zip unzip

RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer
RUN chmod +x /usr/local/bin/composer
RUN composer self-update

RUN sed -i 's/80/${PORT}/g' /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf

ADD conf/apache.conf /etc/apache2/sites-available/000-default.conf

RUN a2enmod rewrite

RUN printf "#!/bin/bash\n/usr/sbin/apache2ctl -D FOREGROUND" > /startScript.sh
RUN chmod +x /startScript.sh

RUN cd /var/www/html
COPY . /var/www/html/
COPY ./.env.example /var/www/html/.env
COPY ./composer.json /var/www/html/composer.json

RUN composer update /var/www/html/ --no-dev --ignore-platform-reqs "vendor/*"
RUN chmod -R 0777 /var/www/html/writable

RUN apt-get clean \
    && rm -r /var/lib/apt/lists/*

EXPOSE ${PORT}
VOLUME ["/var/www/html", "/var/log/apache2", "/etc/apache2"]

CMD ["bash", "/startScript.sh"]

I used apache instead of fpm and it works but I still don't know why fpm is not working

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM