2017-01-09 72 views
1

我想用像遠程服務器一樣的測試來測試我的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= 
+0

DB_HOST應該是你的MySQL服務名'''mysql''' 而不是'''localhost''' –

+0

我找到了答案,謝謝 –

回答

1

你有一個相當複雜的設置一個簡單laravel應用程序。問題是您的laravel應用程序嘗試連接到自己的容器中的MySQL服務器實例。

更改DB_HOST=localhostDB_HOST=mysql而不是連接到mysql容器。

+0

哦,謝謝,它解決了我的問題。 –