title: Can't connect to MySQL docker container
body: <p>I have an issue with my MySQL container, i can't connect to container.</p>
  
  <p>This is my <code>docker-compose.yml</code></p>
  
  <pre><code>apache:
  build: ./
  ports:
      - 1814:80
  volumes:
      - ./code:/app
  links:
      - db
  environment:
      - APACHE_SERVER_NAME=local.dev
      - PHP_SHORT_OPEN_TAG=On
      - PHP_ERROR_REPORTING=E_ALL
      - PHP_DISPLAY_ERRORS=On
      - PHP_HTML_ERRORS=On
  
  db:
  image: mysql:5.6
  ports:
      - "3333:3306"
  volumes:
      - /var/lib/mysql
  environment:
      MYSQL_ROOT_PASSWORD: admin
      MYSQL_DATABASE: app
  </code></pre>
  
  <p>I run with <code>docker-compose up -d --build</code>.</p>
  
  <p>After that, i use <code>docker ps</code> to see running container</p>
  
  <p><a href="https://i.imgsafe.org/3caf28c5f0.png" rel="nofollow noreferrer">https://i.imgsafe.org/3caf28c5f0.png</a></p>
  
  <p>Then i use <code>docker exec -it mddev_apache_1 /bin/bash</code> to running an interactive shell in <code>mddev_apache_1</code> container.</p>
  
  <p>But when i trying to connect to MySQL, its refused.</p>
  
  <p><a href="https://i.imgsafe.org/3ccfde1f73.png" rel="nofollow noreferrer">https://i.imgsafe.org/3ccfde1f73.png</a></p>
  
  <p>Any idea why i can't connect to MySQL container ?</p>
  
  <p>Thanks.</p>
  
  <p>==================================================</p>
  
  <h1>UPDATE</h1>
  
  <p>I change my <code>docker-compose.yml</code> to :</p>
  
  <pre><code>version: '2'
  
  services:
  apache:
      build: ./
      container_name: web-server
      ports:
          - 1814:80
      volumes:
          - ./code:/app
      links:
          - db
      environment:
          - APACHE_SERVER_NAME=local.dev
          - PHP_SHORT_OPEN_TAG=On
          - PHP_ERROR_REPORTING=E_ALL
          - PHP_DISPLAY_ERRORS=On
          - PHP_HTML_ERRORS=On
      networks:
          report:
              aliases:
                  - web-server
  db:
      image: mysql:5.6
      container_name: database
      ports:
          - "3333:3306"
      volumes:
          - /var/lib/mysql
      environment:
          MYSQL_ROOT_PASSWORD: admin
          MYSQL_DATABASE: app
      networks:
          report:
              aliases:
                  - database
  
  networks:
  report:
      driver: bridge
  </code></pre>
  
  <p>But i still can't connect to my MySQL container.</p>
  
  <p><code>http://i.imgsafe.org/4eb89f3857.png</code></p>
  
  <p>I try to inspect my networks and my container.</p>
  
  <p><code>mddev_report</code> network inspect : <code>http://i.imgsafe.org/4eae17a27f.png</code></p>
  
  <p><code>web-server</code> container inspect : <code>http://i.imgsafe.org/4ec74e5d52.png</code></p>
  
  <p><code>database</code> container inspect : <code>http://i.imgsafe.org/4ecb129d2d.png</code></p>