douqian1517
2018-05-09 13:11
浏览 976
已采纳

使用Docker运行Laravel artisan命令时连接被拒绝

I'm running Laravel 5.4 in Docker. This is my docker-compose.yml file:

version: '2'

services:
  app:
    container_name: laravel_app
    image: webdevops/php-apache-dev:ubuntu-16.04
    links:
      - mysql
    depends_on:
      - mysql
    ports:
      - 8888:80
    volumes:
      - .:/app
    environment:
      docker: 'true'
      WEB_DOCUMENT_ROOT: '/app/public'
      WEB_NO_CACHE_PATTERN: '\.(.*)$$'
      working_dir: '/app'
  mysql:
    image: mariadb:latest
    ports:
      - 8889:80
    environment:
      MYSQL_ROOT_PASSWORD: 'dev'
      MYSQL_DATABASE: 'dev'
      MYSQL_USER: 'dev'
      MYSQL_PASSWORD: 'dev'

This is the relevant part of my .env file:

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=8889
DB_DATABASE=dev
DB_USERNAME=dev
DB_PASSWORD=dev

I am able to see the Laravel welcome page - that side of things works. But when I run php artisan migrate I get this error:

SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = dev and table_name = migrations)

I have tried fiddling with the host and port parameters in the .env file.

图片转代码服务由CSDN问答提供 功能建议

我在Docker中运行Laravel 5.4。 这是我的 docker-compose.yml 文件:

  version:'2'
 
services:
 app:
 container_name:laravel_app  
 image:webdevops / php-apache-dev:ubuntu-16.04 
 links:
  -  mysql 
 depends_on:
  -  mysql 
 ports:
  -  8888:80 
卷:
  - 。:  / app 
 environment:
 docker:'true'
 WEB_DOCUMENT_ROOT:'/ app / public'
 WEB_NO_CACHE_PATTERN:'\。(。*)$$'
 working_dir:'/ app'
 mysql:\  n image:mariadb:latest 
 ports:
  -  8889:80 
 environment:
 MYSQL_ROOT_PASSWORD:'dev'
 MYSQL_DATABASE:'dev'
 MYSQL_USER:'dev'
 MYSQL_PASSWORD:'dev'
    
 
 

这是我的 .env 文件的相关部分:

  DB_CONNECTION = mysql  
DB_HOST = mysql 
DB_PORT = 8889 
DB_DATABASE = dev 
DB_USERNAME = dev 
DB_PASSWORD = dev 
   
 
 

我能够看到Laravel欢迎页面 - 那边 事情有效。 但是当我运行 php artisan migrate 时,我收到此错误:

SQLSTATE [HY000] [2002]连接被拒绝(SQL:select * from information_schema.tables where table_schema = dev和table_name = migrations)

我试过摆弄 host port .env 文件中的参数。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题