title: Laravel Docker - SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known
body: <p>In my container when I run <em>php artisan migrate</em> I keep getting this error</p>
  
  <pre><code>In Connector.php line 67:
  
    SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known
  
  
  In Connector.php line 67:
  
    PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known
  </code></pre>
  
  <p>Here's my .ENV file</p>
  
  <pre><code>APP_NAME=Laravel
  APP_ENV=local
  APP_KEY=base64:etukbJpSLgbRsdf5uOEGtLT5Qw+XB6y06Q38HPr
  APP_DEBUG=true
  APP_LOG_LEVEL=debug
  APP_URL=http://127.0.0.1:8000/
  
  DB_CONNECTION=mysql
  DB_HOST=localhost
  DB_PORT=3306
  DB_DATABASE=project
  DB_USERNAME=root
  DB_PASSWORD=
  
  
  BROADCAST_DRIVER=log
  CACHE_DRIVER=file
  SESSION_DRIVER=file
  SESSION_LIFETIME=120
  QUEUE_DRIVER=sync
  
  PUSHER_APP_ID=
  PUSHER_APP_KEY=
  PUSHER_APP_SECRET=
  PUSHER_APP_CLUSTER=mt1
  </code></pre>
  
  <p>I tried to change DB_HOST to mysql but still same result as well as changed it to mariadb</p>
  
  <p>Here's my docker-compose file</p>
  
  <pre><code>version: '3'
  services:
  
   # The Application
    app:
      build:
        context: ./
        dockerfile: app.dockerfile
      working_dir: /var/www
      volumes:
        - ../.:/var/www
        - ./custom.ini:/usr/local/etc/php/conf.d/custom.ini
      environment:
        - "DB_PORT=3306"
        - "DB_HOST=database"
  
   # The Web Server
    web:
      build:
        context: ./
        dockerfile: web.dockerfile
      working_dir: /var/www
      volumes:
        - ../.:/var/www
        - ./vhost.conf:/etc/nginx/conf.d/default.conf
      ports:
        - 8082:80
  
    # The Database
    database:
      image: mysql:5.7
      volumes:
        - dbdata:/var/lib/mysql
      environment:
        MYSQL_USER: ${DB_USERNAME}
        MYSQL_DATABASE: ${DB_DATABASE}
        MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
      ports:
          - "33061:3306"
  
  volumes:
    dbdata:
  </code></pre>
  
  <p>I searched for solution online but none of them helped. Does anyone have a suggestion as to why I keep getting that error?</p>