- У меня есть 2 Laravel проекта, и моя папка структуры (я использую win10)
- docker-compose.yml
- config_projects
- app1.cnf
- app2.cnf
- laravel
- app1 (domain app1.local)
- app2 (domain app2.local)
- Содержимое docker -compose.yml
version: '3.7'
services:
web:
image: nginx
container_name: webserver_laravel
restart: unless-stopped
tty: true
ports:
- "8080:80"
volumes:
- ./:/var/www/laravel
- ./config_projects/app1.conf:/etc/nginx/conf.d/app1.conf
- ./config_projects/app2.conf:/etc/nginx/conf.d/app2.conf
networks:
- laravel
php:
image: php:7.2.5
container_name: php_laravel
restart: unless-stopped
tty: true
volumes:
- ./:/var/www/laravel
networks:
- laravel
db:
image: mysql:5.7
container_name: mysql_laravel
restart: unless-stopped
tty: true
command: --default-authentication-plugin=mysql_native_password
environment:
MYSQL_ROOT_PASSWORD: root
ports:
- "3306:3306"
volumes:
- ./database/mysql:/var/lib/mysql
networks:
- laravel
networks:
laravel:
server {
listen 80;
server_name app1.local;
root /var/www/laravel/app1/public;
index index.php index.html;
charset utf8;
access_log /var/log/nginx/host.access.log main;
location / {
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
if (!-e $request_filename) {
rewrite ^/(.+)$ /index.php?url=$1 last;
break;
}
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
- Содержимое app2.cnf же app1.cnf, просто замените app1 на app2
- Содержимое .env в app1
DB_CONNECTION=mysql
DB_HOST=192.168.56.1 ===> My computer's ip
DB_PORT=3306
DB_DATABASE=app1 ===> is app2 in app2's env
DB_USERNAME=root
DB_PASSWORD=root
- Выполнить docker -compose up -d --build
- Открыть app1.local: 8080 -> works обычно
- Открыть app2.local: 8080 -> SQLSTATE [HY000] [2002] Соединение отклонено
В чем проблема? Большое спасибо