title: Laravel with Docker issue connecting MySQL
body: <p>Steps I follow to setup Laravel using Docker: in my local system I don't have  installed PHP, Composer, Apache, MySQL, phpMyAdmin, etc. I only have Git and Docker install in my system.</p>
  
  <ol>
  <li><p>git clone <a href="https://github.com/laravel/laravel.git" rel="nofollow noreferrer">https://github.com/laravel/laravel.git</a></p></li>
  <li><p>create docker-composer.yml file on project root.</p>
  
  <pre><code>version: "3"
  services:
    db:
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: pass
      MYSQL_DATABASE: db
      MYSQL_USER: root
      MYSQL_PASSWORD: pass
    ports:
      - "3306:3306"
  
  web:
    image: php:7.2.2-apache
    container_name: web_laravel
    depends_on:
      - db
    volumes:
      - ./:/var/www/html/
    ports:
      - "4000:80"
    stdin_open: true
    tty: true
  
  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    depends_on:
      - db
    external_links:
      - db:mysql
    ports:
      - "9191:80"
    environment:
      MYSQL_USER: root
      MYSQL_PASSWORD: pass
      MYSQL_ROOT_PASSWORD: pass
      PMA_HOST: db
  </code></pre></li>
  <li><p>run command from project root. </p>
  
  <pre><code>docker-compose up
  </code></pre>
  
  <p>This command will fetch all the images (php:7.2.2-apache, phpmyadmin/phpmyadmin, mysql:5.7) from local cache or Docker Hub and start three containers for these images.</p>
  
  <p>Now I need to interact with php:7.2.2-apache image's container called web_laravel (see in yml file) so I can add PHP extensions and Composer to run Laravel project.</p></li>
  <li><p>run this command.</p>
  
  <pre><code>docker exec -it web_laravel /bin/bash
  </code></pre>
  
  <p>Now I have access to run any command in running web_laravel container so I've installed Composer and PHP extensions like mbstrings, pdo, pdo_mysql etc.</p>
  
  <p>Then install Laravel dependency using composer install, set permission for storage and bootstrap/cache folders and run php artisan key:generate.</p>
  
  <p>open localhost:4000 and I'm able to see Laravel home page:</p>
  
  <p><a href="https://i.stack.imgur.com/95GY9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/95GY9.png" alt="enter image description here"></a></p></li>
  </ol>
  
  <p>At this point all is good. The problem starts now when I'm connecting to my DB.</p>
  
  <p>Next command to run (I'm still within container):</p>
  
  <pre><code>  php artisan migrate
  </code></pre>
  
  <p>and the errors are:</p>
  
  <pre><code> Illuminate\Database\QueryException  : SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = blog and table_name = migrations)
  
   Illuminate\Database\QueryException  : could not find driver (SQL: select * from information_schema.tables where table_schema = blog and table_name = migrations)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/iOet6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iOet6.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/0H8jd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0H8jd.png" alt="enter image description here"></a></p>
  
  <p>I'm able to open phpMyAdmin (<strong><a href="http://localhost:9191" rel="nofollow noreferrer">http://localhost:9191</a></strong>) and can create DB, table and operations related DB. I've DB called <strong>blog</strong>.</p>
  
  <p>MySQL env variables:</p>
  
  <pre><code>DB_CONNECTION=mysql
  DB_HOST=127.0.0.1
  DB_PORT=3306
  DB_DATABASE=blog
  DB_USERNAME=root
  DB_PASSWORD=pass
  </code></pre>