skip to Main Content

I have php, nginx, mysql, phpmyadmin in Docker and the are running all.
But I can not use any othe them because, when I visit the localhost it shows me the following Error: 502 Bad Gateway

that is the directory of my projet

see all are running
I don’t know why, I tried alot to know the reason but Icound’t figure it out.
That is my Dockerfile

FROM php:8.0-fpm
          
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"




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

default.conf file

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;
    }

    location ~ \.php$ {
        return 404;
    }

}

docker-compose.yml file

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

2

Answers


  1. Maybe the error occurs due php container isn’t running.

    Could you check wich the Dockerfile below?

    FROM php:8.0-fpm
          
    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  "alsbls"
    
    EXPOSE 9000
    
    CMD ["php-fpm"]
    

    After adding the code for php.

    You have to execute the following commadn to solve the problem:

    docker run --rm -v $(pwd)/app:/var/www/infoSystem  -w /var/www/infoSystem -it node:12.13.0 bash
    

    this answer was from @Artem

    Login or Signup to reply.
  2. You are running docker multi-stage build.

    FROM php:8.0-fpm

    ….
    then
    ….

    FROM node:12.13.0

    This doesn’t mean that php-fpm is being merged within single container with node. Multi-stage is being used to mostly to get files from the earlier image. The last "FROM" would be the final image of the container.

    Thus you might want to either remove node / move node earlier / install node differently

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search