Docker composer project can't find/ping or connect to internal hostnames
<p>I'm running a docker project using compose (on Ubuntu 14 for what it's worth) and one of my containers can't find/see/ping/connect to one of my other containers. </p>

<p>The <code>worker</code> container can't ping or connect to the <code>db</code> container, and I can't - for the life of me - understand why. </p>

<p>This is my project: </p>

<p><strong>docker-compose.yml</strong></p>

<pre><code>version: '2'

services:
  web:
    build: ./web
    depends_on:
      - db
    volumes:
      - ./web/:/app/src
    ports:
      - "80:80"
      - "443:443"
  db:
    build: ./db
    volumes:
      - "./.data/db:/var/lib/mysql"
      - ./db/init:/docker-entrypoint-initdb.d
    environment:
      MYSQL_DATABASE: redacted
      MYSQL_USER: redacted
      MYSQL_PASSWORD: redacted
  worker:
    build: ./worker
    volumes:
      - ./worker/:/app
    depends_on:
      - db
</code></pre>

<p><strong>worker/Dockerfile</strong></p>

<pre><code>FROM php:5.6-alpine
RUN docker-php-ext-install pdo_mysql

ADD redacted.php /app/redacted.php
CMD ["/app/redacted.php"]
</code></pre>

<p><strong>worker/redacted.php</strong></p>

<pre><code>echo shell_exec('ping db -c 2');
$dbh = new PDO("mysql:host=db;dbname=redacted", "redacted", "redacted"); 
</code></pre>

<p>The output is:</p>

<pre><code>worker_1  | ping: bad address 'db'
worker_1  | Warning: PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Try again in /app/redacted.php on line 29
worker_1  | SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Try again
</code></pre>