Vite server with laravel app on Docker containers - php

I'm not really sure of how this should work so correct me if I'm wrong because I don't quite know what I'm taling about. I'm having issues hosting a vite server on my Docker dev environment. For now, I have a simple setup for hosting my Laravel/Breeze app with Nginx and a simple MySQL database.
How would you implement a vite server in such architecture?
I have tried installing nodeJS on my Laravel app container (PHP) and running the node dev server but it doesn't seem to host the correct files, I think it is still serving static PHP files.
### ./qa-app/Dockerfile
FROM node:latest
FROM php:8.0-fpm
# Installation de node pour le serveur bundeling de Vite, uniquement pour dev env
COPY --from=node /usr/local/bin/node /usr/local/bin/node
COPY --from=node /usr/local/lib/node_modules /usr/local/lib/node_modules
RUN ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm
# Variables définies dans le fichier docker-compose.yml
ARG user
ARG uid
# Instllation des dépendances
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip
# Vidage du cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Installation des extensions PHP
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
# Utilisation de la dernière version Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Création d'un utilisateur pour executer les commandes Composer et Artisan
RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
chown -R $user:$user /home/$user
# Définition du répertoire de travail
WORKDIR /var/www
USER $user
Those are the services of my Docker dev environment:
/// ./docker-compose.yml
version: "3.7"
services:
app:
build:
args:
user: command-minion
uid: 1000
context: ./qa-app/
dockerfile: Dockerfile
image: qaapp
container_name: qaapp-app
restart: unless-stopped
working_dir: /var/www/
volumes:
- ./qa-app/:/var/www
networks:
- qaapp
db:
image: mysql:8.0
container_name: qaapp-db
restart: unless-stopped
environment:
MYSQL_DATABASE: qaapp
MYSQL_ROOT_PASSWORD: root
MYSQL_PASSWORD: usepwd
MYSQL_USER: use
SERVICE_TAGS: dev
SERVICE_NAME: mysql
ports:
- 3306:3306
volumes:
- ./docker-compose/mysql:/docker-entrypoint-initdb.d
networks:
- qaapp
nginx:
image: nginx:alpine
container_name: qaapp-nginx
restart: unless-stopped
ports:
- 8000:80
volumes:
- ./qa-app/:/var/www
- ./docker-compose/nginx:/etc/nginx/conf.d/
networks:
- qaapp
networks:
qaapp:
driver: bridge
nginx configuration file:
### ./docker-compose/nginx/qaapp.conf
server {
listen 80;
# Définit les fichiers index à servir en priorité
# Si index.php est trouvé dans le répertoire racine, il sera servi, sinon index.html sera servi
index index.php index.html;
# Fichier des logs d'erreur nginx
error_log /var/log/nginx/error.log;
# Fichier des logs d'accès au serveur nginx
access_log /var/log/nginx/access.log;
# Définition du répertoire racine des fichiers à servir
root /var/www/public;
# Configuration pour les requêtes se terminant par ".php"
location ~ \.php$ {
# Essaie de servir le fichier demandé. Si ce n'est pas possible, renvoie une erreur 404
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# Transmet la requête à l'application sur le port 9000
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
# Configuration pour toutes les autres requêtes
location / {
# Essaie de servir le fichier demandé. Si ce n'est pas possible, transmet la requête à /index.php avec les paramètres de requête
try_files $uri $uri/ /index.php?$query_string;
# Active la compression gzip pour les fichiers statiques
gzip_static on;
}
}

Related

Connection refused (error 502) while adding SSH to the php-fpm

I'm using Docker for my Laravel application and now I have to add an SSH connection to the PHP-fpm container to set up Xdebug.
In the PHP docker file in the end if it's added CMD ["/usr/sbin/sshd","-D"] then I'm getting error 502 Bad Gateway.
This is the log:
2023-01-11 00:09:38 2023/01/10 23:09:38 [error] 22#22: *2 connect() failed (111: Connection refused) while connecting to upstream, client: 172.20.0.1, server: 127.0.0.1, request: "GET / HTTP/1.1", upstream: "fastcgi://172.20.0.2:9000", host: "localhost:8000"
Also if I try to make an SSH connection from the CMD, then I'm getting next error:
kex_exchange_identification: Connection closed by remote host
It looks like some collision with the ports, but I'm not sure.
docker-compose.yml
version: '3.8'
services:
server:
build:
context: .
dockerfile: dockerfiles/nginx.dockerfile
ports:
- '8000:80'
volumes:
- ./src:/var/www/html
- ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf:ro
depends_on:
- php
- mysql
php:
build:
context: .
dockerfile: dockerfiles/php.dockerfile
volumes:
- ./src:/var/www/html
- ./php/php-dev.ini:/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
mysql:
platform: linux/x86_64
image: mysql:8.0
ports:
- '3306:3306'
env_file:
- ./env/mysql.env
composer:
build:
context: ./dockerfiles
dockerfile: composer.dockerfile
volumes:
- ./src:/var/www/html
artisan:
build:
context: .
dockerfile: dockerfiles/php.dockerfile
volumes:
- ./src:/var/www/html
entrypoint: ["php", "/var/www/html/artisan"]
npm:
image: node:14
working_dir: /var/www/html
entrypoint: ["npm"]
volumes:
- ./src:/var/www/html
php.dockerfile
FROM php:8.1-fpm-alpine
WORKDIR /var/www/html
COPY src .
RUN docker-php-ext-install pdo pdo_mysql
RUN apk add --update linux-headers \
&& apk add --no-cache $PHPIZE_DEPS \
&& pecl install xdebug \
&& docker-php-ext-enable xdebug
RUN apk --update add --no-cache openssh bash \
&& sed -i s/#PermitRootLogin.*/PermitRootLogin\ yes/ /etc/ssh/sshd_config \
&& echo "root:root" | chpasswd \
&& rm -rf /var/cache/apk/* \
&& sed -ie 's/#Port 22/Port 2000/g' /etc/ssh/sshd_config \
&& sed -ri 's/#HostKey \/etc\/ssh\/ssh_host_key/HostKey \/etc\/ssh\/ssh_host_key/g' /etc/ssh/sshd_config \
&& sed -ir 's/#HostKey \/etc\/ssh\/ssh_host_rsa_key/HostKey \/etc\/ssh\/ssh_host_rsa_key/g' /etc/ssh/sshd_config \
&& sed -ir 's/#HostKey \/etc\/ssh\/ssh_host_dsa_key/HostKey \/etc\/ssh\/ssh_host_dsa_key/g' /etc/ssh/sshd_config \
&& sed -ir 's/#HostKey \/etc\/ssh\/ssh_host_ecdsa_key/HostKey \/etc\/ssh\/ssh_host_ecdsa_key/g' /etc/ssh/sshd_config \
&& sed -ir 's/#HostKey \/etc\/ssh\/ssh_host_ed25519_key/HostKey \/etc\/ssh\/ssh_host_ed25519_key/g' /etc/ssh/sshd_config \
&& /usr/bin/ssh-keygen -A \
&& ssh-keygen -t rsa -b 4096 -f /etc/ssh/ssh_host_key
CMD ["/usr/sbin/sshd","-D"]
#RUN sed -i 's/127.0.0.1:9000/0.0.0.0:9000/g' /usr/local/etc/php-fpm.d/www.conf
ngingx.dockerfile
FROM nginx:stable-alpine
WORKDIR /etc/nginx/conf.d
COPY nginx/nginx.conf .
RUN mv nginx.conf default.conf
WORKDIR /var/www/html
COPY src .
ngingx.conf
server {
listen 80;
index index.php index.html;
server_name 127.0.0.1;
root /var/www/html/public;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}

Dockerized Laravel App, "GET /index.php" but others url works

i'm getting 404 only on my index / url and in the logs there is just GET /index.php from nginx container.
Weird thing is that i can see that the page loaded and it redirect me to 404 instant!
Here's my config :
docker-compose.yaml
version: "3.7"
services:
app:
build:
args:
user: antaku
uid: 1000
context: ./
dockerfile: Dockerfile
image: event
container_name: event-app
restart: unless-stopped
working_dir: /var/www/
volumes:
- ./:/var/www
networks:
- application
nginx:
image: nginx:alpine
container_name: app-nginx
restart: unless-stopped
ports:
- 3000:80
volumes:
- ./:/var/www
- .docker/nginx:/etc/nginx/conf.d/
networks:
- application
depends_on:
- app
networks:
application:
driver: bridge
Dockerfile
FROM php:8.0-fpm
# Arguments defined in docker-compose.yml
ARG user
ARG uid
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
curl \
libpng-dev \
libonig-dev \
libxml2-dev \
zip \
unzip
# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install PHP extensions
RUN docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd
# Get latest Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# 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
# Set working directory
WORKDIR /var/www
USER $user
and nginx.conf located in .docker/nginx
server {
listen 80;
index index.php index.html;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/public;
location ~ \.php$ {
try_files $uri =404;
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_param PATH_INFO $fastcgi_path_info;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
}
Seems duplicated of "GET /index.php" 404 when dockerize Laravel app but we do not have the same structure.

docker 403 forbidden php nginx

docker-compose.yml
version: "3"
networks:
laravel:
services:
nginx:
image: nginx:stable-alpine
container_name: nginx
ports:
- "8088:80"
volumes:
- ./src:/usr/share/nginx/html
- ./site.conf:/etc/nginx/conf.d/site.conf
depends_on:
- php
- mysql
networks:
- laravel
mysql:
image: mysql:5.7.35
container_name: mysql
restart: unless-stopped
tty: true
ports:
- "4306:3306"
volumes:
- ./mysql:/var/lib/mysql
environment:
MYSQL_DATABASE: boilerplatelaravel
MYSQL_USER: root
MYSQL_ROOT_PASSWORD: Tobi12345678
networks:
- laravel
php:
build:
context: .
dockerfile: Dockerfile
container_name: php
volumes:
- ./src/public:/var/www/html
ports:
- "9000:9000"
networks:
- laravel
site.conf
server {
listen 80;
index index.php;
server_name localhost;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/html/public;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
My file tree
testdocker/
┣ mysql/
┣ nginx/
┣ src/
┃ ┗ index.php
┣ docker-compose.yml
┣ Dockerfile
┗ site.conf
When i run a index.html it works fine but when i run a index.php with phpinfo() in it is doesn't work.
2021/09/23 09:02:10 [error] 32#32: *2 directory index of "/usr/share/nginx/html/" is forbidden, client: 172.26.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost:8088"
This is the error i get when i look at the logs.
Based on this https://dariuscoder.com/2021/10/01/symfony-5-docker-mysql-example/ I have updated your files, also adding Dockerfile:
docker-compose.yml:
version: "3"
networks:
laravel:
services:
nginx:
image: nginx:stable-alpine
container_name: nginx
ports:
- "8088:80"
volumes:
- .:/app:cached
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:cached
depends_on:
- php
- mysql
networks:
- laravel
php:
build:
context: .
dockerfile: Dockerfile
volumes:
- .:/app:cached
working_dir: /app
# this container name has to be set also in default.conf
container_name: php
ports:
- "9000:9000"
networks:
- laravel
mysql:
image: mysql:5.7.35
container_name: mysql
restart: unless-stopped
tty: true
ports:
- "4306:3306"
volumes:
- ./mysql:/var/lib/mysql
environment:
MYSQL_DATABASE: boilerplatelaravel
MYSQL_USER: root
MYSQL_ROOT_PASSWORD: Tobi12345678
networks:
- laravel
docker/nginx/default.conf (for some reason did not work with site.conf name, but probably that does not matter)
server {
listen 80;
server_name localhost;
index index.php index.html;
root /app/src;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# container name is php, so php:9000
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location ~ \.php$ {
return 404;
}
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
}
Dockerfile:
FROM php:8.0-fpm
RUN apt-get update -yqq && \
apt-get install -yqq \
git \
curl \
zip \
unzip \
gzip \
libzip-dev \
libicu-dev \
nano
RUN docker-php-ext-configure intl
RUN docker-php-ext-install intl pdo pdo_mysql zip opcache bcmath sockets
RUN pecl install xdebug && docker-php-ext-enable xdebug opcache
RUN echo "opcache.max_accelerated_files = 20000" >> /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \
php composer-setup.php && \
php -r "unlink('composer-setup.php');" && \
mv composer.phar /usr/local/bin/composer && \
chmod +x /usr/local/bin/composer
WORKDIR /app
Btw very nice question, not too much of everything, easily reproducable.

An exception occurred in driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Temporary fai lure in name resolution

I have this error since three days & I tried to know the reason, but I couldn't. I'm beginner in Docker & Symfony.
I made docker containers for php, mysql & nginx in my project directory from this Tutorial , then I installed symfony 5.
When I try to execute the following command inside docker container, where is my project:
bin/console doctrine:database:create
the error after the executing of the command
my directory it's like this:
symfony_docker
app (dir)
symfony files are here
mysql (dir)
nginx (dir)
default.conf (file)
php (dir)
Dockerfile (file)
docker-compose.yml (file)
that is the content of the 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: secret
MYSQL_DATABASE: symfony_docker
MYSQL_USER: symfony
MYSQL_PASSWORD: symfony
ports:
- '4306:3306'
volumes:
- ./mysql:/var/lib/mysql
php:
container_name: php
build:
context: ./php
ports:
- '9000:9000'
volumes:
- ./app:/var/www/symfony_docker
depends_on:
- database
nginx:
container_name: nginx
image: nginx:stable-alpine
ports:
- '8080:80'
volumes:
- ./app:/var/www/symfony_docker
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
- database
That is the content of the php 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/symfony_docker
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 "test#test.com" \
&& git config --global user.name "test"
the content of the default.conf
server {
listen 80;
index index.php;
server_name localhost;
root /var/www/symfony_docker/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;
}
}
content of .env in symfony
# In all environments, the following files are loaded if they exist,
# the latter taking precedence over the former:
#
# * .env contains default values for the environment variables needed by the app
# * .env.local uncommitted file with local overrides
# * .env.$APP_ENV committed environment-specific defaults
# * .env.$APP_ENV.local uncommitted environment-specific overrides
#
# Real environment variables win over .env files.
#
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
#
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration
###> symfony/framework-bundle ###
APP_ENV=dev
APP_SECRET=ace4f16ab212b0206302e83d3939664f
###< symfony/framework-bundle ###
###> doctrine/doctrine-bundle ###
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
#
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
# DATABASE_URL="mysql://db_user:db_password#127.0.0.1:3306/db_name?serverVersion=5.7"
# DATABASE_URL="postgresql://db_user:db_password#127.0.0.1:5432/db_name?serverVersion=13&charset=utf8"
DATABASE_URL="mysql://root:secret#mysql:4306/menukarte?serverVersion=5.7"
###< doctrine/doctrine-bundle ###
I tried already to change the DATABASE_URL= to
#mysql
#localhost
#27.0.0.1
no one of them resolved the issue
thank you very much
I added the host as you said, and I changed the port to 3306 Like this: DATABASE_URL="mysql://root:secret#database:3306/menukarte?serverVersion=5.7" –

Can't see nginx port via "docker ps" command

I have an nginx container up and running (see below picture), but the configured port (8585) is not displaying, as result the related symfony 4 project is not running via localhost:8585
Here is nginx configuration in docker-composer.yml file:
version: "3.6"
services:
#Core configuration
php-fpm:
container_name: ${CONTAINER_NAME}_php-fpm
build:
context: .
target: base
ports:
- '${PHP_PORT}:9000'
volumes:
- './:${WORKPATH}:rw'
- './docker/php/conf/dev/php.ini:/usr/local/etc/php/php.ini'
#- './docker/php/conf/dev/php.ini:/usr/local/etc/php/php.ini'
env_file:
- .env
restart: always
nginx:
container_name: ${CONTAINER_NAME}_nginx
image: nginx
ports:
- '${NGINX_PORT}:80'
volumes:
- './:${WORKPATH}:rw'
- './docker/nginx/logs:/var/log/nginx'
- './docker/nginx/conf/dev/api022020.conf:/etc/nginx/conf.d/default.conf'
#- './docker/nginx/conf/dev/api022020.conf:/etc/nginx/conf.d/default.conf'
- './docker/nginx/conf/core/nginx.conf:/etc/nginx/nginx.conf'
links:
- php-fpm
env_file:
- .env
expose:
- 80
restart: always
# Frontend configuration
node:
container_name: ${CONTAINER_NAME}_node
build: './docker/nodejs'
ports:
- '${NODE_PORT}:3000'
entrypoint: "yarn watch"
volumes:
- './:/usr/src/app:rw'
restart: always
#DB configuration
# For dev environment coding
mysql:
container_name: ${CONTAINER_NAME}_mysql
image: mysql:5.7
ports:
- '${MYSQL_PORT}:3306'
environment:
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
volumes:
- 'mysql:/var/lib/mysql'
restart: always
#For prod environment emulation
postgresql:
container_name: ${CONTAINER_NAME}_pgsql
image: postgres:9.6-alpine
environment:
PGSQL_DATABASE: ${PGSQL_DATABASE}
PGSQL_USER: ${PGSQL_USER}
PGSQL_PASSWORD: ${PGSQL_PASSWORD}
ports:
- '${PGSQL_PORT}:5432'
volumes:
- 'db-data:/var/lib/postgresql/data:rw'
restart: always
#Server optimization
redis:
container_name: ${CONTAINER_NAME}_redis
image: redis:alpine
ports:
- '${REDIS_PORT}:6379'
links:
- php-fpm
restart: always
volumes:
db-data: {}
mysql:
Please check out my nginx .conf file:
server {
listen 80 default_server; # Added this line
listen [::]80 default_server; # Added this line
#server_name my-project.dev;
root /var/www/api022020/public;
location / {
try_files $uri /index.php$is_args$args;
}
#Prod
location ~ ^/index\.php(/|$) {
fastcgi_pass php-fpm:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}
location ~ \.php$ {
return 404;
}
error_log /var/log/nginx/api022020_prod_error.log;
access_log /var/log/nginx/api022020_prod_access.log;
}
.env file:
# In all environments, the following files are loaded if they exist,
# the latter taking precedence over the former:
#
# * .env contains default values for the environment variables needed by the app
# * .env.local uncommitted file with local overrides
# * .env.$APP_ENV committed environment-specific defaults
# * .env.$APP_ENV.local uncommitted environment-specific overrides
#
# Real environment variables win over .env files.
#
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.
#
# Run "composer dump-env prod" to compile .env files for production use (requires symfony/flex >=1.2).
# https://symfony.com/doc/current/best_practices.html#use-environment-variables-for-infrastructure-configuration
###> symfony/framework-bundle ###
APP_ENV=dev
APP_SECRET=5f41c23b077589c815d289434ec7aeb4
#TRUSTED_PROXIES=127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
#TRUSTED_HOSTS='^(localhost|example\.com)$'
###< symfony/framework-bundle ###
###> doctrine/doctrine-bundle ###
# Format described at https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
# For a PostgreSQL database, use: #"postgresql://db_user:db_password#127.0.0.1:5432/db_name?serverVersion=11&charset=utf8"
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
# DATABASE_URL=mysql://root:password#127.0.0.1:3306/db_name?serverVersion=5.7
###< doctrine/doctrine-bundle ###
## Docker
CONTAINER_NAME=api022020
WORKPATH=/var/www/api022020
PHP_PORT=9500
NGINX_PORT=8585
REDIS_PORT=8283
NODE_PORT=8382
MAILDEV_PORT=1080
APACHE_PORT=8189
## MySQL
MYSQL_PORT=3306
MYSQL_DATABASE=api022020
MYSQL_USER=api022020
MYSQL_PASSWORD=api022020
MYSQL_ROOT_PASSWORD=api022020
## POSTGRESQL
PGSQL_PORT=5342
PGSQL_DATABASE=api022020
PGSQL_USER=api022020
PGSQL_PASSWORD=api022020
UPDATE:
Dockerfile:
FROM php:fpm-alpine as base
ENV WORKPATH "/var/www/api022020"
ENV COMPOSER_ALLOW_SUPERUSER 1
RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS icu-dev postgresql-dev libzip-dev gnupg graphviz make autoconf git zlib-dev curl chromium go \
&& docker-php-ext-configure pgsql --with-pgsql=/usr/local/pgsql \
&& docker-php-ext-install zip intl pdo_pgsql pdo_mysql opcache json pgsql mysqli \
&& pecl install apcu redis \
&& docker-php-ext-enable apcu mysqli redis
#Custom php configuration
COPY ./docker/php/conf/dev/php.ini /usr/local/etc/php/php.ini
#Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
RUN wget https://cs.symfony.com/download/php-cs-fixer-v2.phar -o php-cs-fixer \
&& chmod a+x php-cs-fixer \
&& mv php-cs-fixer /usr/local/bin/php-cs-fixer \
&& curl --insecure -LS https://get.sensiolabs.de/deptrac.phar -o deptrac.phar \
&& chmod a+x deptrac.phar \
&& mv deptrac.phar /usr/local/bin/deptrac
RUN mkdir -p ${WORKPATH}
RUN rm -rf ${WORKPATH}/vendor \
&& ls -l ${WORKPATH}
RUN mkdir -p ${WORKPATH}/var \
&& mkdir ${WORKPATH}/var/cache \
&& mkdir ${WORKPATH}/var/logs \
&& mkdir ${WORKPATH}/var/sessions \
&& chown -R www-data ${WORKPATH}/var \
&& chown -R www-data /tmp
RUN chown www-data:www-data -R ${WORKPATH}
WORKDIR ${WORKPATH}
COPY . ./
EXPOSE 9000
CMD ["php-fpm"]
#Production environment
FROM base
COPY ./docker/php/conf/prod/php.ini /usr/local/etc/php/php.ini
UPDATE 2
patrick#patrick-VirtualBox:/var/www/api022020$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0241c049f90c redis:alpine "docker-entrypoint.s…" 22 minutes ago Up 22 minutes 0.0.0.0:8283->6379/tcp api022020_redis
a58155e52d7f nginx "nginx -g 'daemon of…" 22 minutes ago Up 5 minutes 0.0.0.0:8585->80/tcp api022020_nginx
3aab21fb15aa postgres:9.6-alpine "docker-entrypoint.s…" 22 minutes ago Restarting (1) 46 seconds ago api022020_pgsql
0cf51b9359a8 api022020_node "yarn watch" 22 minutes ago Restarting (1) 42 seconds ago api022020_node
087648a69e68 8ee96c1a7995 "docker-php-entrypoi…" 22 minutes ago Up 22 minutes 0.0.0.0:9500->9000/tcp api022020_php-fpm
7de9e9a59252 mysql:5.7 "docker-entrypoint.s…" 22 minutes ago Up 22 minutes 0.0.0.0:3306->3306/tcp, 33060/tcp api022020_mysql
When trying to access localhost:8585, it seems not to work:
This site can’t be reachedThe webpage at http://localhost:8585/ might be temporarily down or it may have moved permanently to a new web address.
ERR_SOCKET_NOT_CONNECTED
UPDATE 3
Getting Bad Request error when replacing nginx image with apache image as following:
Bad Request
Your browser sent a request that this server could not understand.
Apache/2.4.7 (Ubuntu) Server at localhost Port 8189
Apache container configuration:
# Apache
apache:
container_name: ${CONTAINER_NAME}_apache
image: tutum/apache-php
ports:
- "${APACHE_PORT}:80"
volumes:
- '${WORKPATH}:/var/www'
- './docker/php/conf/dev/php.ini:/etc/php5/apache2/conf.d/30-custom.ini'
- './docker/apache/sites:/etc/apache2/sites-enabled'
environment:
- "ALLOW_OVERRIDE=true"
links:
- "mysql:mysql"
- "maildev:maildev"
env_file:
- .env
restart: always
# Maildev
maildev:
image: djfarrelly/maildev
ports:
- "${MAILDEV_PORT}:80"
Any hints as how to fix this issue? Thanks in advance
Maybe forgot to load .env
php-fpm:
...
env_file: # <-- Add this
- .env # <-- Add this
nginx:
...
env_file: # <-- Add this
- .env # <-- Add this
..
Update1:
Make sure the Dockerfile you go EXPOSE 80
docker-compose.yml
nginx:
...
expose:
- 80
...
nginx.conf
server {
listen 80 default_server; # Add this line
listen [::]:80 default_server; # Add this line
#server_name my-project.dev;
root /var/www/api022020/public;
location / {
try_files $uri /index.php$is_args$args;
}
#Prod
location ~ ^/index\.php(/|$) {
fastcgi_pass php-fpm:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}
location ~ \.php$ {
return 404;
}
error_log /var/log/nginx/api022020_prod_error.log;
access_log /var/log/nginx/api022020_prod_access.log;
}
if still not working, can you please provide logs from the failed nginx container docker-componse logs --tail=500
Update2:
How do you load you secret into your environments ? for postgres for example
docker-compose.yml (read https://hub.docker.com/_/postgres)
...
postgresql:
container_name: ${CONTAINER_NAME}_pgsql
image: postgres:9.6-alpine
environment:
POSTGRES_DB: ${PGSQL_DATABASE} # <-- Change the left key
POSTGRES_USER: ${PGSQL_USER} # <-- Change the left key
POSTGRES_PASSWORD: ${PGSQL_PASSWORD} # <-- Change the left key
node:
container_name: ${CONTAINER_NAME}_node
build: './docker/nodejs'
ports:
- '${NODE_PORT}:3000'
entrypoint: "yarn watch" # <-- change "entrypoint" by "command"
volumes:
- './:/usr/src/app:rw'
restart: always
...
Have you update your nginx.conf to listen a port ? (I gave you lines on update1)
Update3:
My fault, syntax error:
listen [::]80 default_server; -> listen [::]:80 default_server;

Categories