0

I am trying to run my Laravel app in ECS Fargate. I created following docker file for my laravel app:

FROM composer:lts as vendor
WORKDIR /app
COPY . ./
RUN composer install \
    --ignore-platform-reqs \
    --no-interaction \
    --no-plugins \
    --no-scripts \
    --prefer-dist


FROM node:18 as ui
ENV NODE_OPTIONS=--max-old-space-size=16384
WORKDIR /app
COPY . ./
RUN npm install
RUN npm run production

FROM php:8.2-fpm-bullseye as app

ENV DEBIAN_FRONTEND noninteractive

####################### install required softwares
RUN apt-get update && apt-get upgrade -y && apt-get install -y \
    gzip \
    zip \
    unzip \
    curl \
    libfreetype-dev \
    libjpeg62-turbo-dev \
    libwebp-dev \
    libzip-dev \
    libldap2-dev \
    libcurl4-openssl-dev \
    libpng-dev \
    libjpeg-dev \
    libonig-dev \
    libssl-dev \
    default-mysql-client \
    wget \
    supervisor

RUN apt-get install -y \
    nginx \
    # for imap
    libc-client-dev \
    libkrb5-dev \
    && rm -r /var/lib/apt/lists/*

# Fix timezone
RUN set -eux && echo "date.timezone=UTC" > /usr/local/etc/php/php.ini

####################### install extensions
# configure gd
RUN docker-php-ext-configure gd --with-jpeg=/usr/include/ --with-webp=/usr/include/ --with-freetype=/usr/include/
# install pecl ext: redis, igbinary, msgpack
RUN pecl install redis igbinary msgpack
# install ldap, zip, mbstring, imap, curlm gd, pdo_mysql
RUN docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/
RUN docker-php-ext-configure imap --with-kerberos --with-imap-ssl
RUN docker-php-ext-install ldap zip mbstring imap curl gd pdo_mysql
RUN docker-php-ext-enable redis igbinary msgpack

RUN apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false && \
    rm -rf /tmp/* /var/tmp/*

####################### copy files
COPY . /var/www/html
COPY --from=vendor ./app/vendor /var/www/html/vendor/
COPY --from=ui ./app/public /var/www/html/public/
RUN chown www-data:www-data /var/www/html -R

####################### config for php
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
COPY ./docker/aws/php.ini  /usr/local/etc/php/conf.d/override.ini
COPY ./docker/aws/www.conf /usr/local/etc/php/php-fpm.d/www.conf

####################### config for supervisor
COPY ./docker/aws/supervisord.nginx.fpm.prod.conf /etc/supervisor/conf.d/supervisord.conf
COPY ./docker/aws/start-container.aws /usr/local/bin/start-container
RUN chmod +x /usr/local/bin/start-container

####################### config for nginx
COPY ./docker/aws/default.aws.conf /etc/nginx/sites-available/default

RUN cp .env.example .env

####################### errors to stderr
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
    && ln -sf /dev/stderr /var/log/nginx/error.log \
    && ln -sf /dev/stderr /var/log/php8.1-fpm.log

ENTRYPOINT ["start-container"]

and start-container script:

#!/usr/bin/env bash
php -i 
/usr/bin/supervisord

and supervisor

[supervisord]
nodaemon=true
user=root
logfile=/var/log/supervisor/supervisord.log
pidfile=/var/run/supervisord.pid

[program:phpfpm]
priority=3
autostart=true
autorestart=true
stderr_logfile_maxbytes=0
stdout_logfile_maxbytes=0
stdout_events_enabled=true
stderr_events_enabled=true
command=php-fpm -F
stderr_logfile=/dev/stderr
stdout_logfile=/dev/stdout

[program:nginx]
priority=1
autostart=true
autorestart=true
stdout_events_enabled=true
stderr_events_enabled=true
command=/usr/sbin/nginx -g 'daemon off;'
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

using this configuration whenever my app starts with multiple tasks, some of the ECS Tasks do not get fully functional. they show timeout in the browser if you use their IP address. No specific Error appears in the ECS Task Log. it only happens when I try to create multiple tasks.

I tried to log everything as much as possible, but sometimes I see 499 errors in the ECS Task Log.

I used a bash code to curl inside my docker to see if the php-fpm is working. I found that despite the supervisor says the php-fpm is running it looks like is not respoding.

I do not know what iI supposed to do.

Hadi Aghandeh
  • 765
  • 6
  • 24
  • 1
    499 means the client closed the connection. Maybe some JavaScript or timeout. See https://stackoverflow.com/q/12973304/492773 – kichik Jul 22 '23 at 14:41
  • I understand what 499 means. We don't have any timeout on the client side. we also increased all execution times to be sure that timeout is not the case. – Hadi Aghandeh Jul 22 '23 at 14:58

0 Answers0