我有一个laravel应用,我使用docker在本地开发来创建容器。
这已经工作了几个月,在过去的两个月中我还没有开发过该应用程序,但是今天当我启动容器时,我无法再从php实例与数据库实例进行通信。我可以使用计算机上的本地主机地址连接到服务器,但是当我尝试在php容器上执行任何操作(例如,用户登录到应用程序)时,连接就会被拒绝。
因此,总而言之,我可以从笔记本电脑中迁移php artisan并创建表格,然后查看站点(localhost:8080),并显示登录屏幕,然后尝试登录并得到以下错误:>
Illuminate \ Database \ QueryException(2002)SQLSTATE [HY000] [2002] 连接被拒绝(SQL:从
users
中选择*,其中users
。deleted_at
为空限制1)
我已将我的所有文件都包括在下面
.env
APP_NAME=Laravel
APP_ENV=local
APP_KEY=**REMOVED**
APP_DEBUG=true
APP_URL=https://localhost:8443
APP_CDN=true
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=33061
DB_DATABASE=dockerApp
DB_USERNAME=root
DB_PASSWORD=secret
docker-compose.yml
version: '2'
services:
nginx:
image: nginx:1.13.12
ports:
- "8443:443"
- "8080:80"
volumes:
- ./:/var/www
- ./nginxconf:/etc/nginx/conf.d
- ./ssl-cert:/etc/nginx/certs
working_dir: /var/www
links:
- php
php:
build:
context: ./
dockerfile: app.docker
volumes:
- ./:/var/www
links:
- db
environment:
- "DB_PORT=3306"
- "DB_HOST=db"
db:
image: mysql:5.7
environment:
- "MYSQL_ROOT_PASSWORD=secret"
- "MYSQL_DATABASE=dockerApp"
ports:
- "33061:3306"
app.docker
FROM php:7-fpm
RUN apt-get update && apt-get install -y libmcrypt-dev mysql-client \
&& docker-php-ext-install pdo_mysql \
&& pecl install mcrypt-1.0.1 docker-php-ext-enable mcrypt
WORKDIR /var/www
vhost.conf
server {
listen 80;
root /var/www/public;
location / {
try_files $uri /index.php?$args;
}
location ~\.php$ {
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;
}
}
server {
listen 443;
ssl on;
root /var/www/public;
ssl_certificate /var/www/ssl-cert/server.crt;
ssl_certificate_key /var/www/ssl-cert/server.key;
ssl_password_file /var/www/ssl-cert/passwords.txt;
ssl_client_certificate /var/www/ssl-cert/ca.crt;
ssl_verify_client on;
}