Reputation: 762
I want to test my laravel project with the same inviroment like remote server. So i try to use Docker (never know before). I installed docker, and follow the instruction in project to deploy it with docker. Setup
Copy file .env.example to .env, docker-compose.yml.example to docker-compose.yml
Modify .env config file (optional). If you modify the mysql, mongo, redis configurations in .env file, remember to modify the configurations in docker-compose.yml file too. Install or run Docker
docker-compose up -d
// Stop
docker-compose stop
chmod cache folders
chmod -R 777 storage
chmod -R 777 bootstrap/cache
Deploy
sh deploy.sh
After running sh doploy.sh
i got this error:
[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
File "docker-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
File ".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=
Upvotes: 1
Views: 1350
Reputation: 5767
You have quite a complex setup for a simple laravel application. The problem is that your laravel app tries to connect to a MySQL
server instance in its own container.
Change DB_HOST=localhost
to DB_HOST=mysql
to connect to the mysql
container instead.
Upvotes: 2