使用Docker部署laravel项目时发生mysql错误
问题描述:
我想用像远程服务器一样的测试来测试我的laravel项目。所以我尝试使用Docker(以前从未知道)。我安装了docker,并按照项目中的说明使用docker进行部署。 设置使用Docker部署laravel项目时发生mysql错误
复制文件.env.example到.ENV,搬运工,compose.yml.example到泊坞窗,compose.yml
修改.ENV配置文件(可选)。如果在.env文件中修改mysql,mongo,redis配置,请记住修改docker-compose.yml文件中的配置。 安装或运行泊坞
docker-compose up -d
//停止
docker-compose stop
搭配chmod缓存文件夹
chmod -R 777 storage
chmod -R 777 bootstrap/cache
部署
sh deploy.sh
运行sh doploy.sh
后我得到这个错误:
[Illuminate\Database\QueryException]
SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = awesome_teacher and table_name = migrations)
[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[HY000] [2002] No such file or directory
[PDOException]
SQLSTATE[HY000] [2002] No such file or directory
[Illuminate\Database\QueryException]
SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables w
here table_schema = homestead_test and table_name = migrations)
[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[HY000] [2002] No such file or directory
[PDOException]
SQLSTATE[HY000] [2002] No such file or directory
文件 “泊坞窗,compose.yml”:
version: '2'
### Change the `teacher` with your own teacher name ###
services:
application:
container_name: teacher_application
image: debian
volumes:
- ./:/var/www/laravel
workspace:
container_name: teacher_workspace
restart: always
image: my_company/laravel-workspace
volumes_from:
- application
tty: true
php-fpm:
container_name: teacher_php-fpm
restart: always
image: my_company/laravel-php-fpm
volumes_from:
- application
expose:
- "9000"
links:
- workspace
nginx:
container_name: teacher_nginx
restart: always
image: my_company/laravel-nginx
volumes_from:
- data
- logs
- application
ports:
- "8000:80"
links:
- php-fpm
data:
container_name: teacher_data
image: debian
volumes:
- .docker/mysql:/var/lib/mysql
- .docker/data:/data
data_test:
container_name: teacher_data_test
image: debian
volumes:
- .docker/mysql_test:/var/lib/mysql
- .docker/data_test:/data
logs:
container_name: teacher_logs
image: debian
volumes:
- .docker/logs/nginx:/var/log/nginx
- .docker/logs/mongodb:/var/log/mongodb
mysql:
container_name: teacher_mysql
restart: always
image: mysql
volumes_from:
- data
- logs
expose:
- "3306"
environment:
MYSQL_DATABASE: awesome_teacher
MYSQL_USER: root
MYSQL_PASSWORD: blablabla
MYSQL_ROOT_PASSWORD: blablabla
mysql_test:
container_name: teacher_mysql_test
restart: always
image: mysql
volumes_from:
- data_test
expose:
- "3306"
environment:
MYSQL_DATABASE: homestead_test
MYSQL_USER: homestead_test
MYSQL_PASSWORD: secret
MYSQL_ROOT_PASSWORD: root
文件 “.ENV”:
APP_ENV=local
APP_KEY=base64:hl4qkfCdHiJrCG4sGfYfMU8faq3WywMHkH+mr/FiDu9PM=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=awesome-teacher.local
APP_DOMAIN='awesome-teacher.local'
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=awesome_teacher
DB_USERNAME=root
DB_PASSWORD=blablabla
DB_TEST_CONNECTION=mysql_test
DB_TEST_HOST=localhost
DB_TEST_PORT=3308
DB_TEST_DATABASE=homestead_test
DB_TEST_USERNAME=homestead_test
DB_TEST_PASSWORD=secret
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
PUSHER_APP_ID=
PUSHER_KEY=
PUSHER_SECRET=
答
你有一个相当复杂的设置一个简单laravel应用程序。问题是您的laravel应用程序尝试连接到自己的容器中的MySQL
服务器实例。
更改DB_HOST=localhost
到DB_HOST=mysql
而不是连接到mysql
容器。
+0
哦,谢谢,它解决了我的问题。 –
DB_HOST应该是你的MySQL服务名'''mysql''' 而不是'''localhost''' –
我找到了答案,谢谢 –