无法 运行 artisan 使用 docker-compose 设置进行迁移
Cannot run artisan migrate with docker-compose setup
我已经进行了以下设置,无法理解为什么我的 docker-composer run --rm artisan migrate
正在努力连接到数据库并显示以下错误消息:
错误:
Illuminate\Database\QueryException
SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'172.28.0.4' (using password:
YES) (SQL: select * from information_schema.tables where table_schema = homestead and tabl
e_name = migrations and table_type = 'BASE TABLE')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:669
665| // If an exception occurs when attempting to run a query, we'll format the error
666| // message to include the bindings with SQL, which will make this exception a
667| // lot more helpful to the developer instead of just the database's errors.
668| catch (Exception $e) {
> 669| throw new QueryException(
670| $query, $this->prepareBindings($bindings), $e
671| );
672| }
673|
Laravel版本:v7.3.0
Docker 编写设置:
version: '3'
networks:
laravel:
services:
nginx:
image: nginx:stable-alpine
container_name: nginx
ports:
- "8080:80"
volumes:
- ./src:/var/www/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
- mysql
networks:
- laravel
mysql:
image: mysql:5.7.29
container_name: mysql
restart: unless-stopped
tty: true
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: homestead
MYSQL_USER: homestead
MYSQL_PASSWORD: secret
MYSQL_ROOT_PASSWORD: secret
SERVICE_TAGS: dev
SERVICE_NAME: mysql
networks:
- laravel
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
ports:
- "8183:80"
depends_on:
- mysql
environment:
PMA_HOST: mysql
PMA_PORT: "3306"
PMA_ARBITRARY: 1
MYSQL_PASSWORD: secret
restart: unless-stopped
networks:
- laravel
php:
build:
context: .
dockerfile: Dockerfile
container_name: php
volumes:
- ./src:/var/www/html
ports:
- "9000:9000"
networks:
- laravel
composer:
image: composer:latest
container_name: composer
volumes:
- ./src:/var/www/html
working_dir: /var/www/html
depends_on:
- php
networks:
- laravel
npm:
image: node:13.7
container_name: npm
volumes:
- ./src:/var/www/html
working_dir: /var/www/html
entrypoint: ['npm']
artisan:
build:
context: .
dockerfile: Dockerfile
container_name: artisan
volumes:
- ./src:/var/www/html
depends_on:
- mysql
working_dir: /var/www/html
entrypoint: ['/var/www/html/artisan']
networks:
- laravel
MySQL .env 中的配置:
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secure
所有配置对我来说都是正确的,因为我可以通过 phpmyadmin 查看数据库。
到目前为止,我已经尝试过重建图像和刷新缓存,正如其他 Whosebug 问题所建议的那样,但这似乎对我也不起作用。
任何关于我哪里出错的提示,将不胜感激。
您将 MySQL 密码设置为 secret
而它在您的 .env
文件中是 secure
我已经进行了以下设置,无法理解为什么我的 docker-composer run --rm artisan migrate
正在努力连接到数据库并显示以下错误消息:
错误:
Illuminate\Database\QueryException
SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'172.28.0.4' (using password:
YES) (SQL: select * from information_schema.tables where table_schema = homestead and tabl
e_name = migrations and table_type = 'BASE TABLE')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:669
665| // If an exception occurs when attempting to run a query, we'll format the error
666| // message to include the bindings with SQL, which will make this exception a
667| // lot more helpful to the developer instead of just the database's errors.
668| catch (Exception $e) {
> 669| throw new QueryException(
670| $query, $this->prepareBindings($bindings), $e
671| );
672| }
673|
Laravel版本:v7.3.0
Docker 编写设置:
version: '3'
networks:
laravel:
services:
nginx:
image: nginx:stable-alpine
container_name: nginx
ports:
- "8080:80"
volumes:
- ./src:/var/www/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
- mysql
networks:
- laravel
mysql:
image: mysql:5.7.29
container_name: mysql
restart: unless-stopped
tty: true
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: homestead
MYSQL_USER: homestead
MYSQL_PASSWORD: secret
MYSQL_ROOT_PASSWORD: secret
SERVICE_TAGS: dev
SERVICE_NAME: mysql
networks:
- laravel
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
ports:
- "8183:80"
depends_on:
- mysql
environment:
PMA_HOST: mysql
PMA_PORT: "3306"
PMA_ARBITRARY: 1
MYSQL_PASSWORD: secret
restart: unless-stopped
networks:
- laravel
php:
build:
context: .
dockerfile: Dockerfile
container_name: php
volumes:
- ./src:/var/www/html
ports:
- "9000:9000"
networks:
- laravel
composer:
image: composer:latest
container_name: composer
volumes:
- ./src:/var/www/html
working_dir: /var/www/html
depends_on:
- php
networks:
- laravel
npm:
image: node:13.7
container_name: npm
volumes:
- ./src:/var/www/html
working_dir: /var/www/html
entrypoint: ['npm']
artisan:
build:
context: .
dockerfile: Dockerfile
container_name: artisan
volumes:
- ./src:/var/www/html
depends_on:
- mysql
working_dir: /var/www/html
entrypoint: ['/var/www/html/artisan']
networks:
- laravel
MySQL .env 中的配置:
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secure
所有配置对我来说都是正确的,因为我可以通过 phpmyadmin 查看数据库。
到目前为止,我已经尝试过重建图像和刷新缓存,正如其他 Whosebug 问题所建议的那样,但这似乎对我也不起作用。
任何关于我哪里出错的提示,将不胜感激。
您将 MySQL 密码设置为 secret
而它在您的 .env
文件中是 secure