'Bad Gateway nginx container 502

I'm trying sine one week to figure out what is the reason to get this error 502 Bad Gateway!!.

I have in Dockerfile command for PHP and yarn. In docker-composse file images for nginx - mysql - phpmyadmin&encore. That is my  directory, where is my project.

Could some one hekp me? When I delete the code of yarn in Docker file and rebuild the container it works.

docker-cómpose.yml
version: '3.3'

services:
  database:
    container_name: database
    image: mysql:8.0
    restart: always
    command: --default-authentication-plugin=mysql_native_password
    environment:
      MYSQL_ROOT_PASSWORD: alsbls
      MYSQL_DATABASE: infoSystem
      MYSQL_USER: alsbls
      MYSQL_PASSWORD: alsbls
    ports:
      - '4306:3306'
    volumes:
      - ./mysql:/var/lib/mysql

  php:
    container_name: php
    restart: always
    build:
      context: ./php
    ports:
      - '9000:9000'
    volumes:
      - ./app:/var/www/infoSystem

    depends_on:
      - database

  nginx:
    container_name: nginx
    image: nginx:stable-alpine
    restart: always
    ports:
      - '8080:80'
    volumes:
      - ./app:/var/www/infoSystem
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      - php
      - database

  phpmyadmin:
    image: phpmyadmin/phpmyadmin:latest
    restart: always
    environment:
      PMA_HOST: database
      PMA_USER: alsbls_root
      PMA_PASSWORD: alsbls_root
    ports:
      - "8081:81"

  encore:
    container_name: node
    restart: always
    build:
      context: ./php
    volumes:
      - ./app:/var/www/infoSystem

default.conf file for nginx

server {

    listen 80;
    index index.php;
    server_name localhost;
    root /var/www/infoSystem/public;
    error_log /var/log/nginx/project_error.log;
    access_log /var/log/nginx/project_access.log;

    location / {
        try_files  $uri /index.php$is_args$args;
    }

    location ~ ^/index\\.php(/|$) {
        fastcgi_pass php:9000;
        fastcgi_split_path_info ^(.+\\.php)(/.*)$;
        include fastcgi_params;

        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;

        fastcgi_buffer_size 128k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;

        internal;
    }

}

Dockerfile

RUN apt update   \
            && apt install -y zlib1g-dev g++ git libicu-dev zip libzip-dev zip \
            && docker-php-ext-install intl opcache pdo pdo_mysql \
            && pecl install apcu \
            && docker-php-ext-enable apcu \
            && docker-php-ext-configure zip \
            && docker-php-ext-install zip
WORKDIR /var/www/infoSystem
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN curl -sS https://get.symfony.com/cli/installer | bash
RUN mv /root/.symfony/bin/symfony /usr/local/bin/symfony
RUN git config --global user.email "[email protected]" \
        && git config --global user.name  "test"

EXPOSE 9000

CMD ["php-fpm"]
    
    
    FROM node:12.13.0
    RUN apt update
    WORKDIR /var/www/infoSystem
    COPY entrypoint.sh /usr/local/bin/entrypoint
    RUN ["chmod", "+x", "/usr/local/bin/entrypoint"]
    ENTRYPOINT ["/usr/local/bin/entrypoint"]
    USER node

entrypoint.sh file

#!/bin/bash
# Prevent container from shutting down
while true; do sleep 3600; done


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source