无法通过docker-compose安装程序运行artisan迁移

时间:2020-04-04 12:18:17

标签: mysql laravel docker docker-compose laravel-artisan

我已经按照以下设置进行操作,无法理解为什么我的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

.env中的MySQL配置:

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secure

所有配置对我来说似乎都是正确的,因为我可以通过phpmyadmin查看数据库。

到目前为止,我尝试过的是重建图像和刷新缓存,如其他stackoverflow问题所建议的那样,但这似乎对我也不起作用。

任何关于我做错地方的提示,将不胜感激。

1 个答案:

答案 0 :(得分:0)

{ "title": "rust", "author": "AniketFuryRocks", "image": { "src": "https://upload.wikimedia.org/wikipedia/commons/thumb/1/1f/Norco_Range.jpg/2560px-Norco_Range.jpg" }, "contentBody": [ "as","asd" ] } 文件中将MySQL密码设置为secret时将MySQL密码设置为secure