Ngnix server giving 502 error when using supervisor - php

There is problem with Docker when using supervisor . Actually server doesn't give any error . When starting supervisor emerges problems which when enter site giving 502 errors !
When uncomment follow code in image php giving error
#ENTRYPOINT ["supervisord", "-c", "/etc/supervisor/supervisord.conf"]
Follow docker.yml
services:
webapp:
build:
context: .
dockerfile: Docker/php/prod.Dockerfile
image: webapp:php
container_name: webapp
restart: always
tty: true
stdin_open: true
volumes:
- ./Docker/php/ini/volume_conf.prod.conf:/usr/local/etc/php/conf.d/volume_conf.prod.conf
- ./Docker/php/supervisor/supervisord.conf:/etc/supervisor/supervisord.conf
- ./Docker/php/supervisor/multiProductRunner.conf:/etc/supervisor/conf.d/multiProductRunner.conf
- ./Docker/php/supervisor/crawlingProductsRunner.conf:/etc/supervisor/conf.d/crawlingProductsRunner.conf
#- ./Docker/php/supervisor/start-container:/usr/local/bin/start-container
- ./source/:/var/www/html
networks:
customnetwork:
ipv4_address: 172.20.0.10
db:
build:
context: .
dockerfile: ./Docker/mysql/Dockerfile
image: mariadb
container_name: db
restart: always
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: 'root'
MYSQL_ROOT_HOST: "%"
MYSQL_DATABASE: ''
MYSQL_USER: 'user'
MYSQL_PASSWORD: 'password'
MYSQL_ALLOW_EMPTY_PASSWORD: 1
volumes:
- ./Docker/mysql/volume/:/var/lib/mysql
networks:
customnetwork:
ipv4_address: 172.20.0.11
healthcheck:
test: [ "CMD", "mysqladmin", "ping", "-p password" ]
retries: 3
timeout: 5s
nginx:
image: nginx:alpine
container_name: nginx
tty: true
volumes:
- ./source/:/var/www/html
- ./Docker/nginx/:/etc/nginx/conf.d/
ports:
- "9001:80"
networks:
customnetwork:
ipv4_address: 172.20.0.12
meilisearch:
image: 'getmeili/meilisearch:latest'
ports:
- '7700:7700'
volumes:
- './Docker/meilisearch/volume/:/meili_data'
networks:
customnetwork:
ipv4_address: 172.20.0.13
healthcheck:
test: ["CMD", "wget", "--no-verbose", "--spider", "5"]
retries: 3
timeout: 5s
networks:
customnetwork:
ipam:
config:
- subnet: 172.20.0.0/16
PHP version 8.1 image file (problem is there
FROM php:8.1-fpm
# PHP extensions
RUN apt-get update
RUN apt-get install -y build-essential libssl-dev zlib1g-dev libpng-dev libjpeg-dev libfreetype6-dev
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN docker-php-ext-install pdo pdo_mysql gd
RUN apt-get install -y \
libzip-dev \
zip \
&& docker-php-ext-install zip
RUN echo 'memory_limit = -1' >> /usr/local/etc/php/conf.d/docker-php-memlimit.ini
RUN apt-get remove supervisor --yes
RUN apt-get install supervisor --yes
RUN service supervisor start
#COPY ./Docker/php/supervisor/multiProductRunner.conf /etc/supervisor/conf.d/supervisord.conf
#COPY ./Docker/php/supervisor/start-container /usr/local/bin/start-container
#RUN chmod +x /usr/local/bin/start-container
# when uncomment follow code giving error
#ENTRYPOINT ["supervisord", "-c", "/etc/supervisor/supervisord.conf"]
#EXPOSE 9000

Related

Deploying a Laravel project with docker gives a user permission error

I have a docker compose and Dockerfile, when building the project builds and the containers run but gives the site gives the error:
The stream or file "/var/www/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file "/var/www/storage/logs/laravel.log" could not be opened in append mode
docker-compose.yml:
version: '3'
services:
#PHP Service
app:
build:
context: .
dockerfile: Dockerfile
image: digitalocean.com/php
container_name: app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www
volumes:
- ./:/var/www
- ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- app-network
#Nginx Service
webserver:
image: nginx:alpine
container_name: webserver
restart: unless-stopped
tty: true
ports:
- "80:80"
- "443:443"
volumes:
- ./:/var/www
- ./nginx/conf.d/:/etc/nginx/conf.d/
networks:
- app-network
#MySQL Service
db:
image: mysql:5.7.22
container_name: db
restart: unless-stopped
tty: true
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: laravel
MYSQL_ROOT_PASSWORD: password
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- dbdata:/var/lib/mysql/
- ./mysql/my.cnf:/etc/mysql/my.cnf
networks:
- app-network
#Docker Networks
networks:
app-network:
driver: bridge
#Volumes
volumes:
dbdata:
driver: local
Dockerfile:
FROM php:8.1-fpm
# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/
# Set working directory
WORKDIR /var/www
# Install dependencies
RUN apt-get update && apt-get install -y \
build-essential \
mysql-client \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
nano \
curl \
libzip-dev
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/
RUN docker-php-ext-install gd
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www
COPY . /var/www/
COPY --chown=www:www . /var/www
USER www
EXPOSE 9000
CMD ["php-fpm"]
"docker-compose exec app chown -R www-data:www-data /var/www"
solved my problem

PHP Pest (with Laravel) tests running very slow in OSX Docker

I was developing an app locally using Laravel. For testing I was using Pest and tests were running fast, really fast. That was until I decided to Dockerize my app, now tests are running pretty slow.
What it used to run in 3 seconds now it's running in over a minute.
Here's my Dockerfile:
FROM php:8.1.12-fpm
ARG uid=1000
ARG user=macgiver
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip
# Install and enable xDebug
RUN pecl install xdebug \
&& docker-php-ext-enable xdebug
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install php modules required by laravel.
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
# Create system user to run Composer and Artisan commands.
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
chown -R $user:$user /home/$user
# Install composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Set working directory
WORKDIR /var/www
USER $user
and this is my docker-compose:
version: "3.9"
services:
app:
build:
context: ./
dockerfile: Dockerfile
image: dmc
container_name: dmc-app
restart: unless-stopped
working_dir: /var/www/
depends_on:
- db
- nginx
volumes:
- ./:/var/www/
- ./docker/php/conf.d/xdebug.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
- ./docker/php/conf.d/error_reporting.ini:/usr/local/etc/php/conf.d/error_reporting.ini
expose:
- "9003"
networks:
- dmc-net
nginx:
image: nginx:1.23.2-alpine
container_name: dmc-nginx
restart: unless-stopped
ports:
- "8000:80"
volumes:
- ./:/var/www
- ./docker-compose/nginx:/etc/nginx/conf.d
networks:
- dmc-net
db:
image: mysql:8.0.31
container_name: dmc-db
restart: unless-stopped
# using 3307 on the host machine to avoid collisions in case there's a local MySQL instance installed already.
ports:
- "3307:3306"
# use the variables declared in .env file
environment:
MYSQL_HOST: ${DB_HOST}
MYSQL_DATABASE: ${DB_DATABASE}
MYSQL_PASSWORD: ${DB_PASSWORD}
MYSQL_ROOT_PASSWORD: abcd1234
MYSQL_USER: ${DB_USERNAME}
SERVICE_TAGS: dev
SERVICE_NAME: mysql
volumes:
- ./docker-compose/mysql:/docker-entrypoint-initdb.d
- mysql-data:/var/lib/mysql
networks:
- dmc-net
networks:
dmc-net:
driver: bridge
volumes:
mysql-data:
Any ideas?

Why Laravel App in Docker response with 404 status code

I have a laravel application on a docker container
In my local windows development environment it works correctly. When I take the docker container to the ubuntu linux test server the index.php return 404 response code when i run docker compose up command in ubuntu terminal
docker_compose.yml
version: "3.9"
services:
#Nginx Service
webserver:
image: nginx:1.21.6-alpine
container_name: webserver-maderas
restart: unless-stopped
tty: true
ports:
- "8082:80"
- "444:443"
volumes:
- ./src:/var/www/
configs:
- source: nginx_config
target: /etc/nginx/conf.d/default.conf
networks:
- app-network
node:
image: node:16-alpine
working_dir: /var/www
container_name: node-maderas
volumes:
- ./src:/var/www
- /var/www/node_modules
configs:
- source: node_script
target: /var/www/node_start.sh
command: sh /var/www/node_start.sh
depends_on:
- app
networks:
- app-network
db:
image: mariadb:10.7.3-focal
container_name: db-maderas
restart: unless-stopped
tty: true
ports:
- "3308:3306"
environment:
MARIADB_DATABASE: ${MARIADB_DATABASE}
MARIADB_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD}
volumes:
- dbdata:/var/lib/mysql/
networks:
- app-network
# adminer:
# image: adminer
# restart: always
# ports:
# - 8080:8080
# networks:
# - app-network
app:
build:
context: .
dockerfile: Dockerfile
image: php:8.1-fpm-alpine3.14
container_name: app-maderas
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www
volumes:
- ./src:/var/www/
networks:
- app-network
networks:
app-network:
name: network.local
driver: bridge
configs:
nginx_config:
file: ./nginx/conf.d/default.conf
node_script:
file: ./node/node_start.sh
volumes:
dbdata:
driver: local
Dockerfile
FROM php:8.1-fpm-alpine
WORKDIR /var/www/public
RUN apk update \
&& apk upgrade \
&& apk add --no-cache \
freetype-dev \
libjpeg-turbo-dev \
libmcrypt-dev \
libpng-dev
RUN docker-php-ext-configure gd --with-freetype --with-jpeg
RUN docker-php-ext-install mysqli pdo pdo_mysql gd
RUN docker-php-ext-enable pdo_mysql
RUN addgroup -g 1000 -S www && adduser -u 1000 -S www -G www
COPY --chown=www:www ./src/ /var/www
USER www
EXPOSE 9000
CMD ["php-fpm"]

Problem in docker images it is not starting

I made in my project nginx, mysql, phpMyadmin, encore and php images.
Just php and encore dosent work, they are successed built, but the are with red color.
The directory of the project:
that is my docker-compose.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: encore
restart: always
build:
context: ./php
volumes:
- ./:/var/www/html
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 "devojob97#gmail.com" \
&& git config --global user.name "alsbls"
FROM node:12.10.0
WORKDIR /var/www/html
COPY entrypoint.sh /usr/local/bin/entrypoint
RUN ["chmod", "+x", "/usr/local/bin/entrypoint"]
ENTRYPOINT ["/usr/local/bin/entrypoint"]
USER node
that is the entrypoint.sh in the same dir of Dockerfile:
#!/bin/bash
# Prevent container from shutting down
while true; do sleep 3600; done
I didn't receive any error message on the terminal.
Maybe some one now the issues.
Best regards
I saw in the docker log of the encore image the following error:
standard_init_linux.go:190: exec user process caused "no such file or directory" - Docker
And then I tried to use the following command outside of the container:
dos2unix your-file.sh
This tutorial helped me to solve it:

PHP is not detected in PHP Interpreters, PhpStorm 2020.3, Laravel 8

What I am trying to do:
I am trying to run/debug unit tests within PhpStorm 2020.3, on Laravel 8. The ENV is WSL 2 on Windows 10.
Problem(s)
One: PHP and Xdebug is not detected when I select the service in CLI interpreters.
Two: When I run/debug unit tests, I get different errors, one of which:
[docker-compose://[\\wsl$\Ubuntu-20.04\home\musa\codes\boom\finance\docker-compose.yml]:laravel.test/]:php /opt/.phpstorm_helpers/phpunit.php --configuration /var/www/html/phpunit.xml
Testing started at 8:31 PM ...
Version mismatch: file \\wsl$\Ubuntu-20.04\home\musa\codes\xyz\docker-compose.yml specifies version 3.9 but extension file C:\Users\musah\AppData\Local\JetBrains\PhpStorm2020.3\tmp\docker-compose.override.9.yml uses version 1
Process finished with exit code 1
I suppose the 2nd problem will be fixed if I can fix the first one.
Details:
docker-compose.yml file:
services:
laravel.test:
build:
context: ./docker/development
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP:-wwwdata}'
image: sail-8.0/app
ports:
- '${APP_PORT:-80}:80'
- '9003:9003'
environment:
WWWUSER: '${WWWUSER:-wwwdata}'
LARAVEL_SAIL: 1
volumes:
- '.:/var/www/html'
- './docker/development/xdebug.ini:/usr/local/etc/php/conf.d/php-ext-xdebug.ini'
- './docker/development/php.ini:/usr/local/etc/php/conf.d/99-sail.ini'
- './docker/development/http.conf:/etc/apache2/sites-available/000-default.conf'
- './docker/development/supervisord.conf:/etc/supervisor/conf.d/supervisord.conf'
networks:
- sail
depends_on:
- mysql
- redis
- selenium
mysql:
image: mysql:5.7.29
restart: unless-stopped
tty: true
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
volumes:
- ./docker/development/mysql:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: '${DB_PASSWORD}'
MYSQL_DATABASE: '${DB_DATABASE}'
MYSQL_USER: '${DB_USERNAME}'
MYSQL_PASSWORD: '${DB_PASSWORD}'
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
SERVICE_NAME: mysql
networks:
- sail
healthcheck:
test: ["CMD", "mysqladmin", "ping"]
redis:
image: 'redis:alpine'
ports:
- '${FORWARD_REDIS_PORT:-6379}:6379'
volumes:
- 'sailredis:/data'
networks:
- sail
healthcheck:
test: ["CMD", "redis-cli", "ping"]
mailhog:
image: 'mailhog/mailhog:latest'
ports:
- '${FORWARD_MAILHOG_PORT:-1025}:1025'
- '${FORWARD_MAILHOG_DASHBOARD_PORT:-8025}:8025'
networks:
- sail
selenium:
image: 'selenium/standalone-chrome:latest'
volumes:
- '/dev/shm:/dev/shm'
networks:
- sail
localstack:
image: localstack/localstack:latest
environment:
- AWS_DEFAULT_REGION=us-east-1
- EDGE_PORT=4566
- SERVICES=lambda,s3
ports:
- '4566:4566'
volumes:
- "${TMPDIR:-/tmp/localstack}:/tmp/localstack"
- "/var/run/docker.sock:/var/run/docker.sock"
networks:
- sail
networks:
sail:
driver: bridge
volumes:
sailmysql:
driver: local
sailredis:
driver: local
sailmeilisearch:
driver: local
docker/development/Dockerfile file:
FROM php:8.0-apache
ARG WWWGROUP
WORKDIR /var/www/html
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update \
&& apt-get install -y curl zip unzip supervisor libcap2-bin libpng-dev python2 \
&& php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
&& apt-get -y autoremove \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN pecl install xdebug && docker-php-ext-enable xdebug
RUN setcap "cap_net_bind_service=+ep" /usr/local/bin/php
RUN groupadd --force -g $WWWGROUP sail
RUN useradd -ms /bin/bash --no-user-group -g $WWWGROUP -u 1337 sail
COPY start-container /usr/local/bin/start-container
RUN chmod +x /usr/local/bin/start-container
EXPOSE 8000
EXPOSE 9003
ENTRYPOINT ["start-container"]
docker/development/php.ini file:
[PHP]
post_max_size = 100M
upload_max_filesize = 100M
variables_order = EGPCS
docker/development/xdebug.ini file:
[XDebug]
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.client_host = host.docker.internal
xdebug.client_port = 9003
xdebug.log = "/tmp/xdebug.log"
docker/development/supervisord.conf file:
[supervisord]
nodaemon=true
user=root
logfile=/var/log/supervisor/supervisord.log
pidfile=/var/run/supervisord.pid
[program:php]
command=/usr/local/bin/php -d variables_order=EGPCS /var/www/html/artisan serve --host=0.0.0.0 --port=80
user=sail
environment=LARAVEL_SAIL="1"
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
docker/development/start-container file:
#!/usr/bin/env bash
if [ ! -z "$WWWUSER" ]; then
usermod -u $WWWUSER sail
fi
if [ ! -d /.composer ]; then
mkdir /.composer
fi
chmod -R ugo+rw /.composer
if [ $# -gt 0 ];then
exec gosu $WWWUSER "$#"
else
/usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
fi
To my surprise both the problems were fixed by specifying the version in docker-compose.yml file as:
version: '3.9'
services:
laravel.test:
build:
context: ./docker/development
dockerfile: Dockerfile
args:
...
Reference: https://youtrack.jetbrains.com/issue/PY-38394

Categories