title: Docker php_network_getaddresses error
body: <p>I have following Docker containers running that were generated by <a href="https://phpdocker.io/generator" rel="noreferrer">PHPDocker</a>:</p>
  
  <pre><code>learn-php-mysql:
    image: mysql:5.7
    container_name: learn-php-mysql
    volumes:
      - "./.data/db:/var/lib/mysql"
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: learning
      MYSQL_DATABASE: learning
      MYSQL_USER: learning
      MYSQL_PASSWORD: learning
  
  learn-php-webserver:
    image: phpdockerio/nginx:latest
    container_name: learn-php-webserver
    volumes:
      - ./code:/code
      - ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf
    ports:
     - "8080:80"
    links:
     - learn-php-php-fpm
  
  learn-php-php-fpm:
    build: .
    dockerfile: php-fpm/Dockerfile
    container_name: learn-php-php-fpm
    volumes:
      - ./code:/code
      - ./php-fpm/php-ini-overrides.ini:/etc/php/7.1/fpm/conf.d/99-overrides.ini
    links:
      - learn-php-mysql:mysql
  </code></pre>
  
  <p>Everything works fine, except for when trying to connect to MySQL server via PHP code:</p>
  
  <pre><code>$mysqli = new mysqli("db", "learning", "learning", "learning");
  
  /* check connection */
  if ($mysqli-&gt;connect_errno) {
      printf("Connect failed: %s\n", $mysqli-&gt;connect_error);
      exit();
  }
  </code></pre>
  
  <p>It will throw following error:</p>
  
  <blockquote>
    <p>Connect failed: php_network_getaddresses: getaddrinfo failed: Name or
    service not known</p>
  </blockquote>
  
  <h2>Why does this happen?</h2>
  
  <p>.</p>
  
  <p>.</p>
  
  <p>You can find repository for this <a href="https://github.com/genert/learn-php" rel="noreferrer">here</a>. And when running <code>docker-compose up</code> go to <em><a href="http://localhost:8080/classes/serialize.php" rel="noreferrer">http://localhost:8080/classes/serialize.php</a></em> to produce same error.</p>