- docker-compose.yml
- config_projects
- app1.cnf
- app2.cnf
- laravel
- app1 (domain app1.local)
- app2 (domain app2.local)
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;
}
}
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
是什么问题?非常感谢
最佳答案
谢谢你们我修好了它。这是Laravel不是Docker的问题
在将问题发布到stackoverflow之前,我已经运行了许多下面的命令
php artisan clear-compiled
php artisan cache:clear
php artisan key:generate
php artisan config:clear
php artisan view:clear
php artisan optimize
但这不起作用。现在我重新运行,它可以正常工作。好奇怪
关于php - SQLSTATE [HY000] [2002]在Docker中运行多个laravel项目时,连接被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61136794/