Why Laravel App in Docker response with 404 status code - php

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"]

Related

I run CakePHP application in Docker and I got this message in the browser "This page isn’t working"

I have an existing CakePHP project and I want to run it with Docker,
I used the command docker compose up -d and I got those containers:
Containers List in Docker
Now Obviously, it should be work on localhost:9000 and the phpmyadmin on localhost:8083.
But only the PMA (phpmyadmin) worked, and that what I got in my browser for localhost:9000
Browser Response
So this what I am facing.
DockerFile
FROM phpdockerio/php74-fpm:latest
# Install selected extensions and other stuff
RUN apt-get update \
&& apt-get -y --no-install-recommends install php7.4-mysql php7.4-intl php7.4-mbstring php7.4-sqlite3\
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
WORKDIR "/var/www/html"
docker-compose.yml
version: "3.8"
services:
nginx-proxy:
image: nginx
volumes:
- ./website:/var/www/html
- /var/run/docker.sock:/tmp/docker.sock:ro
- ./docker/log:/var/log/nginx
- ./docker/certs:/etc/nginx/certs
- ./docker/nginx:/etc/nginx/conf.d
ports:
- 80:80
- 443:443
depends_on:
- php
- db
php:
build: ./docker/php/
image: php:fpm
ports:
- 9000:9000
container_name: talkto_php
environment:
- VIRTUAL_HOST=talkto_php.local
depends_on:
- db
volumes:
- ./website:/var/www/html
- ./docker/apache/apache2.conf:/etc/apache2/apache2.conf
db:
image: mysql:5.6.51
container_name: talkto_db
environment:
MYSQL_ROOT_PASSWORD: calltode
MYSQL_USER: talkto
MYSQL_PASSWORD: talkto
MYSQL_DATABASE: talkto
ports:
- "3306:3306"
volumes:
- talkto-data:/var/lib/mysql
- ./database/calltode_dev2.sql:/home/db.sql
pma:
image: phpmyadmin/phpmyadmin
container_name: pma
environment:
PMA_HOST: db
PMA_PORT: 3306
PMA_ARBITRARY: 1
restart: always
ports:
- 8083:80
links:
- db
volumes:
talkto-data:
It suppose to show me the contain of my CakePHP application on localhost:9000

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?

Ngnix server giving 502 error when using supervisor

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

"No releases available" error when installing pecl in Docker

I am trying to install Xdebug or Redis package in a Docker container from pecl. Installation failed and returns an error:
There are no releases available for package "pecl.php.net/xdebug".
Example for Xdebug: https://pecl.php.net/package/xdebug/3.1.0
My docker-compose.yaml
version: '3'
networks:
app-network:
services:
site:
build:
context: .
dockerfile: nginx.dockerfile
container_name: my_nginx
ports:
- "8082:80"
- "443:443"
volumes:
- ./src:/var/www/html
depends_on:
- php
- db
- redis
networks:
- app-network
db:
image: percona
container_name: my_db
restart: on-failure
tty: true
ports:
- "3314:3306"
volumes:
- ./percona:/var/lib/percona
environment:
MYSQL_DATABASE: mydb
MYSQL_USER: me
MYSQL_PASSWORD: 123
MYSQL_ROOT_PASSWORD: 456
SERVICE_TAGS: dev
SERVICE_NAME: db
networks:
- app-network
php:
build:
context: .
dockerfile: php.dockerfile
container_name: my_php
volumes:
- ./src:/var/www/html
ports:
- "9000:9000"
networks:
- app-network
composer:
image: frojd/composer-php-7.4
container_name: my_composer
volumes:
- ./src:/var/www/html
working_dir: /var/www/html
depends_on:
- php
networks:
- app-network
redis:
image: redis:alpine
container_name: my_redis
volumes:
- ./redis:/data
restart: on-failure
command: redis-server --appendonly yes --requirepass "${REDIS_PASSWORD}"
ports:
- 6380:6379
networks:
- app-network
npm:
image: node:14.18.0
container_name: my_npm
volumes:
- ./src:/var/www/html
working_dir: /var/www/html
entrypoint: ['npm']
artisan:
build:
context: .
dockerfile: php.dockerfile
container_name: my_artisan
volumes:
- ./src:/var/www/html
depends_on:
- db
working_dir: /var/www/html
entrypoint: ['php', '/var/www/html/artisan']
networks:
- app-network
cron:
build:
context: .
dockerfile: cron.dockerfile
container_name: my_cron
volumes:
- ./src:/var/www/html
networks:
- app-network
My php.dockerfile
FROM php:7.4-fpm
WORKDIR /var/www/html
RUN apt-get update && \
apt-get install ca-certificates && \
apt-get clean
RUN docker-php-ext-install pdo pdo_mysql
RUN pecl install xdebug \
&& docker-php-ext-enable xdebug \
&& echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.remote_host = host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
What is the cause of the error and how can I fix it?
You may be behind a proxy... I resolved this same problem by setting the proxy for PECL specifically (the environment variable alone $HTTP_PROXY won't work).
RUN pear config-set http_proxy ${http_proxy} &&\
pear config-set php_ini $PHP_INI_DIR/php.ini
RUN pecl install xdebug-3.1.1 && docker-php-ext-enable xdebug
This answer helped me: https://stackoverflow.com/a/11195778/256762. Hope mine's help as well 😉.

Unable to use phpredis with Docker. gives Redis class not found

I have set up php-fpm, redis, nginx and mysql. Now that I want to use php redis extension, I am getting Redis class not found error.
My php docker file:
# php-fpm
FROM php:fpm-alpine
RUN docker-php-ext-install pdo_mysql
ARG INSTALL_PHPREDIS=false
RUN if [ ${INSTALL_PHPREDIS} = true ]; then \
# Install Php Redis Extension
pecl install -o -f redis \
&& rm -rf /tmp/pear \
&& docker-php-ext-enable redis \
;fi
CMD ["php-fpm"]
EXPOSE 9000
My docker-composer.yml:
version: '2'
services:
php-fpm:
build:
context: ./php-fpm
volumes:
- ../src:/var/www
nginx:
build:
context: ./nginx
volumes:
- ../src:/var/www
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/sites/:/etc/nginx/sites-available
- ./nginx/conf.d/:/etc/nginx/conf.d
ports:
- "80:80"
- "443:443"
depends_on:
- php-fpm
database:
build:
context: ./database
environment:
- MYSQL_DATABASE=mydb
- MYSQL_USER=myuser
- MYSQL_PASSWORD=secret
- MYSQL_ROOT_PASSWORD=docker
cache:
build:
context: ./redis
ports:
- "6379:6379"
I want to use redis extension in my php. Not sure what I am missing.

Categories