title: Getting "php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution" error when using docker-compose to build containers
body: <p>It seems as if my php container cannot resolve the host "db" of my database container when I run <code>php artisan migrate</code>, I'm wondering if I've set something up wrong in the config.</p>
  
  <p>Tried messing with the depends_on: and links: options on the dockerfile.</p>
  
  <p>docker-compose.yml</p>
  
  <pre><code>version: '3.3'
  
  services:
    db:
      container_name: tasks-db
      image: mariadb:latest
      volumes:
        - dbdata:/var/lib/mysql
      environment:
        - MYSQL_ROOT_PASSWORD=password
        - MYSQL_DATABASE=tasks
        - MYSQL_USER=root
        - MYSQL_PASSWORD=password
      restart: always
  
    webserver:
      container_name: tasks-webserver
      image: nginx:latest
      ports:
        - "8080:80"
        - "443:443"
      volumes:
        - .:/app
        - ./provision/nginx/:/etc/nginx/conf.d/
      depends_on:
        - php
      restart: always
  
    php:
      container_name: tasks-php
      build:
        context: .
        dockerfile: provision/php.docker
      depends_on:
        - db
      restart: always
      env_file:
        - .env
  
  volumes:
    dbdata:
      driver: local
  </code></pre>
  
  <p>provision/db.docker</p>
  
  <pre><code>FROM php:7.3-fpm
  
  # Add dependencies
  RUN apt-get update -y &amp;&amp; apt-get install -y openssl libpng-dev libxml2-dev curl cron git libzip-dev zip unzip
  
  # Install php extensions
  RUN docker-php-ext-install pdo mbstring gd xml pdo_mysql zip
  
  # Install composer
  RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
  
  COPY . /app/
  
  WORKDIR /app
  
  RUN chown -R $USER:www-data /app/storage
  RUN chown -R $USER:www-data /app/bootstrap/cache
  
  RUN chmod -R 775 /app/storage
  RUN chmod -R 775 /app/bootstrap/cache
  
  # Install composer dependencies
  RUN composer install
  
  RUN php artisan optimize
  
  #RUN php artisan migrate --seed
  
  RUN crontab -l | { cat; echo "* * * * * php /app/artisan schedule:run &gt;&gt; /dev/null 2&gt;&amp;1"; } | crontab -
  
  STOPSIGNAL SIGTERM
  
  CMD ["php-fpm"]
  </code></pre>
  
  <p>db.docker</p>
  
  <pre><code>FROM mariadb:latest
  
  CMD ["mysqld", "--user=mysql"]
  </code></pre>
  
  <p>I'm getting this error:</p>
  
  <pre><code>Step 13/16 : RUN php artisan migrate --no-interaction --seed
   ---&gt; Running in ccbfcde9324d
  
     Illuminate\Database\QueryException  : SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution (SQL: select * from information_schema.tables where table_schema = tasks and table_name = migrations and table_type = 'BASE TABLE')
  
    at /app/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
      660|         // If an exception occurs when attempting to run a query, we'll format the error
      661|         // message to include the bindings with SQL, which will make this exception a
      662|         // lot more helpful to the developer instead of just the database's errors.
      663|         catch (Exception $e) {
    &gt; 664|             throw new QueryException(
      665|                 $query, $this-&gt;prepareBindings($bindings), $e
      666|             );
      667|         }
      668|
  
    Exception trace:
  
    1   PDOException::("PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution")
        /app/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
  
    2   PDO::__construct("mysql:host=db;port=3306;dbname=tasks", "root", "password", [])
        /app/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
  
    Please use the argument -v to see more details.
  ERROR: Service 'php' failed to build: The command '/bin/sh -c php artisan migrate --no-interaction --seed' returned a non-zero code: 1
  </code></pre>