title: Laravel in Docker giving 'php_network_getaddresses: getaddrinfo failed: Name does not resolve'
body: <p>I am having an issue with my Laravel in Docker.</p>
  <p>Currently when I run <code>php artisan migrate</code> <strong>inside</strong> my container I get the error</p>
  <pre><code>SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name does not 
  resolve (SQL: select * from information_schema.tables where table_schema = 
  app_database and table_name = migrations and table_type = 'BASE TABLE')
  </code></pre>
  <p>However, I am able to connect to the mysql using Sequel Pro and I am able to see the database created <code>app_database</code></p>
  <p>My docker_compose.yml is as below:</p>
  <pre><code>version: '3'
  
  
  services:
    nginx:
      build:
        context: .
        dockerfile: Dockerfile_nginx
      container_name: nginx_webserver
      restart: unless-stopped
      ports:
        - &quot;8080:80&quot;
      volumes:
        - ./src:/var/www
        - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
      depends_on:
        - php
        - database
      networks:
        - laravel
  
    database:
      image: mysql:8.0
      container_name: docker_database
      environment:
        - &quot;MYSQL_DATABASE=app_database&quot;
        - &quot;MYSQL_USER=app_db_user&quot;
        - &quot;MYSQL_PASSWORD=app_db_password&quot;
        - &quot;MYSQL_ROOT_PASSWORD=password&quot;
      volumes:
        - ./mysql/db_data:/var/lib/mysql
      ports:
        - &quot;3306:3306&quot;
  
    php:
      build:
        context: .
        dockerfile: Dockerfile_php
      container_name: my_app
      volumes:
        - ./src:/var/www
        - ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
      ports:
        - &quot;9000:9000&quot;
      networks:
        - laravel
      depends_on:
        - database
  
  networks:
    laravel:
      driver: bridge
  </code></pre>
  <p>The .env of my laravel app is</p>
  <pre><code>DB_CONNECTION=mysql
  DB_HOST=docker_database
  DB_PORT=3306
  DB_DATABASE=app_database
  DB_USERNAME=app_db_user
  DB_PASSWORD=app_db_password
  </code></pre>
  <p>Can anybody share some insight?</p>
  <p>I have tried everything online.</p>