title: Docker Compose - Cant connect to MySQL from separate Nginx container
body: <p>I'm struggling with the following docker setup.. everything runs on its own fine but for some reason my nginx container can't connect to the mysql one, I've followed countless tutorials on this and none of them work for me so any advice would be excellent.. my docker compose is as follows (fpm and nginx work perfectly)..  </p>
  
  <pre><code># web server
  nginx:
    image: nginx:latest
    ports:
      - "80:80"
      - "443:443" 
    volumes:
      # app
      - ./app/src:/usr/share/nginx/html
      # nginx configs
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
      - ./nginx/conf.d/:/etc/nginx/conf.d/:ro
      - ./nginx/snippets/:/etc/nginx/snippets/:ro    
      # certificates
      - ./nginx/letsencrypt/fullchain.pem:/etc/letsencrypt/live/example.com/fullchain.pem:ro
      - ./nginx/letsencrypt/privkey.pem:/etc/letsencrypt/live/example.com/privkey.pem:ro
      # logs    
      # - ./logs/nginx-error.log:/var/log/nginx/error.log
      # - ./logs/nginx-access.log:/var/log/nginx/access.log    
    links:
      - fpm:__DOCKER_PHP_FPM__
      - db
  # php-fpm
  fpm:
    build: ./php-fpm
    ports:
      - "9000"
    volumes:
      - ./app/src:/usr/share/nginx/html
      - ./php-fpm/php-production.ini:/usr/local/etc/php/php.ini:ro
  db:
    image: mysql
    environment:
      MYSQL_ROOT_PASSWORD: "admin"
    ports:
      - "3306:3306"      
  </code></pre>
  
  <p>when I run docker-compose up mysql splurts out a couple of interesting lines</p>
  
  <pre><code>    db_1     | 2017-08-01T17:53:15.872664Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
      db_1     | 2017-08-01T17:53:15.872716Z 0 [Note] IPv6 is available.
      db_1     | 2017-08-01T17:53:15.872723Z 0 [Note]   - '::' resolves to '::';
      db_1     | 2017-08-01T17:53:15.872736Z 0 [Note] Server socket created on IP: '::'.
      db_1     | 2017-08-01T17:53:15.911242Z 0 [Note] mysqld: ready for connections.
      db_1     | Version: '5.7.19'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)
  </code></pre>
  
  <p>looks like it's not accepting TCP connections and using the socket address in my wp-config.php database file doesn't work either.</p>
  
  <p>This is basically what is coming up on the wordpress install screen:</p>
  
  <pre><code> Warning: mysqli_real_connect(): (HY000/2002): Connection refused in /usr/share/nginx/html/wp-includes/wp-db.php on line 1538
  </code></pre>
  
  <p>Interestingly I can connect to the database no problem from either SequelPro or MySQL workbench.. Im very new to docker (and docker compose) so maybe I'm missing something or a step here?</p>
  
  <p>I'm running docker on osx if that matters.</p>
  
  <p>docker ps outputs:</p>
  
  <pre><code>    CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS              PORTS                                      NAMES
      060ac535e91e        nginx:latest           "nginx -g 'daemon ..."   9 minutes ago       Up 9 minutes        0.0.0.0:80-&gt;80/tcp, 0.0.0.0:443-&gt;443/tcp   dockerlnmpmaster_nginx_1
      56db5e7bf9c1        mysql                  "docker-entrypoint..."   10 minutes ago      Up 9 minutes        0.0.0.0:3306-&gt;3306/tcp                     dockerlnmpmaster_db_1
      6b8d6e4bec5f        dockerlnmpmaster_fpm   "php-fpm"                10 minutes ago      Up 9 minutes        0.0.0.0:32813-&gt;9000/tcp                    dockerlnmpmaster_fpm_1
  </code></pre>