title: Not able to connect to mysql container from php container
body: <p>I am having 2 docker containers for php app and mysql. Both are working perfectly individually. I can access my php app at <code>localhost:8000</code> and can connect mysql at <code>localhost:3306</code> using MySQL Workbench.</p>
  
  <p>But, my php app which is inside the container is not able to connect to the mysql db which is inside another container.</p>
  
  <p>My docker-compose.yml file is as follows:</p>
  
  <pre><code>    version: '3'
      services:
        website:
          container_name: php-app
          image: php-app
          build:
            context: ./
          volumes:
            - php-app:/var/www/html/
          ports:
            - 8000:80
          depends_on:
            - mysql
        mysql:
          image: mysql:8.0
          container_name: mysql-server-80
          command: --default-authentication-plugin=mysql_native_password
          volumes:
            - .:/application
          restart: always
          environment:
            - MYSQL_ROOT_PASSWORD=123456
            - MYSQL_DATABASE=testdb
            - MYSQL_USER=root
            - MYSQL_PASSWORD=123456
          ports:
            - "3306:3306"
      volumes:
        jayde-ci:
        mysql:
  </code></pre>
  
  <p>My database configuration file inside the codeigniter based php app is as follows:</p>
  
  <pre><code>    $db['default'] = array(
          'dsn'   =&gt; '',
          'hostname' =&gt; 'mysql',
          'username' =&gt; 'root',
          'password' =&gt; '123456',
          'database' =&gt; 'test',
          'dbdriver' =&gt; 'mysqli',
          'dbprefix' =&gt; '',
          'pconnect' =&gt; FALSE,
          'db_debug' =&gt; (ENVIRONMENT !== 'production'),
          'cache_on' =&gt; FALSE,
          'cachedir' =&gt; '',
          'char_set' =&gt; 'utf8',
          'dbcollat' =&gt; 'utf8_general_ci',
          'swap_pre' =&gt; '',
          'encrypt' =&gt; FALSE,
          'compress' =&gt; FALSE,
          'stricton' =&gt; FALSE,
          'failover' =&gt; array(),
          'save_queries' =&gt; TRUE
      );
  </code></pre>