502 Bad Gateway error v5

I am having issue of “502 Bad Gateway”.

nginx file.

    server {
    listen 80 default_server;
    server_name pay.mydomain.com;

    client_max_body_size 100M;

    gzip on;
    gzip_types      application/javascript application/x-javascript text/javascript text/plain appl    ication/xml application/json;
    gzip_proxied    no-cache no-store private expired auth;
    gzip_min_length 1000;

    root /var/www/app/public/;
    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass app:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
    fastcgi_buffers 4 16k;
      }
    }

docker-compose file

version: '3.7'
services:
  server:
    image: nginx
    restart: always
    env_file: ./env.env
    volumes:
      - ./ninja_volume/config/nginx/in-vhost.conf:/etc/nginx/conf.d/in-vhost.conf:ro
      - ./ninja_volume/app/public:/var/www/app/public:ro
    depends_on:
      - app
    networks:
      - reverse-proxy
    labels:
      - traefik.enable=true
      - traefik.http.routers.pay.rule=Host(`pay.mydomain.com`)
      - traefik.http.routers.pay.entrypoints=websecure
      - traefik.http.routers.pay.tls.certresolver=leresolver  
  app:
    image: invoiceninja/invoiceninja:5
    env_file: ./env.env
    restart: always
    volumes:
      - ./ninja_volume/config/hosts:/etc/hosts:ro
      - ./ninja_volume/app/public:/var/www/app/public:rw,delegated
      - ./ninja_volume/app/storage:/var/www/app/storage:rw,delegated
    networks:
      - reverse-proxy
networks:
  reverse-proxy:
    external: true

Env file

# IN application vars
APP_URL=https://pay.mydomain.com
# docker run --rm -it invoiceninja/invoiceninja php artisan key:generate --show
APP_KEY=base64:xxxxxx
APP_DEBUG=false
REQUIRE_HTTPS=true


PHANTOMJS_PDF_GENERATION=false

OPENEXCHANGE_APP_ID=xxxxxx


# DB connection
# mysql
DB_HOST=msql
DB_PORT=3306
DB_DATABASE=xxxxxx
DB_USERNAME=xxxxxx
DB_PASSWORD=xxxxxx

# Create initial user
# Default to these values if empty
IN_USER_EMAIL=xxxxxx
IN_PASSWORD=xxxxxx
# IN_USER_EMAIL=
# IN_PASSWORD=

# Mail options
MAIL_MAILER=log
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS='xxxxxx@mydomain.com'
MAIL_FROM_NAME='xxxxxxr'

# MySQL
MYSQL_ROOT_PASSWORD=xxxxxx
MYSQL_USER=xxxxxx
MYSQL_PASSWORD=xxxxxx
MYSQL_DATABASE=xxxxxx

  
TRUSTED_PROXIES='*'

All happened after doing update with.

docker-compose down
docker-compose pull
docker-compose up

in app log

2021-07-01T12:12:12Z [ERROR] [Entrypoint]: Error connecting to DB
2021-07-01T12:12:12Z [INFO] [Entrypoint]: Initialising Invoice Ninja...
Configuration cache cleared!
Configuration cached successfully!
Configuration cache cleared!
Configuration cached successfully!
Route cache cleared!
Routes cached successfully!
Files cached successfully!
In Connection.php line 692:
  SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from inform  
  ation_schema.tables where table_schema = ninja and table_name = accounts an  
  d table_type = 'BASE TABLE')                                                 
In Exception.php line 18:
  SQLSTATE[HY000] [2002] No such file or directory  
In PDOConnection.php line 39:
  SQLSTATE[HY000] [2002] No such file or directory  

also tried - but not worked.
php artisan optimize

Hi,

Maybe try running php artisan migrate

nope not working,
in log:
app_1 |
app_1 | In Connection.php line 692:
app_1 |
app_1 | SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from inform
app_1 | ation_schema.tables where table_schema = ninja and table_name = accounts an
app_1 | d table_type = ‘BASE TABLE’)
app_1 |
app_1 |
app_1 | In Exception.php line 18:
app_1 |
app_1 | SQLSTATE[HY000] [2002] No such file or directory
app_1 |
app_1 |
app_1 | In PDOConnection.php line 39:
app_1 |
app_1 | SQLSTATE[HY000] [2002] No such file or directory
app_1 |
app_1 |

BTW connection info is true,

@david do you have any suggestions?

Here is a full example of a working Traefik config

Traefik is ok, invoice ninja was working fine, the issue started to occur after doing the last invoiceninja update(dc down/pull/up), also i did update on MySQL.

I solved it

In env file

there was,
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=xxxxx
DB_USERNAME=xxxxx
DB_PASSWORD=xxxxx

and then added following lines.
DB_HOST1=172.xx.xx.xx ← ip of mysql container.
DB_PORT1=3306
DB_DATABASE1=xxxxx
DB_USERNAME1=xxxxx
DB_PASSWORD1=xxxxx

Inspired from
In issue #368 there is mentioned Code part line 39

Thanks for sharing the solution!

cc @david