title: ERROR 2002 (HY000): Can't connect to MySQL server on 'db' (115)
body: <p>I am trying to move existing project to Docker. I followed this tutorial at <a href="https://courses.m.academy/courses/set-up-magento-2-development-environment-docker/lectures/9283467" rel="nofollow noreferrer">M.Academy</a> and followed the setup instructions from <a href="https://github.com/markshust/docker-magento#existing-projects" rel="nofollow noreferrer">Docker on Existing Project</a></p>
  <p>While executing trying to connect with MySQL I am getting this error <strong>ERROR 2002 (HY000): Can't connect to MySQL server on 'db' (115)</strong></p>
  <p>I also tried to execute: <code>telnet db 3306</code></p>
  <p>Response:
  Trying 172.17.0.1...
  telnet: Unable to connect to remote host: Connection timed out</p>
  <p>I tried everything but couldn't figure out the problem. I am new to Docker. I am using Ubuntu 18.04 LTE. Haven't changed db.env and got no error on any other step before importing the database.</p>
  <p>I further checked and found out that the container is not able to establish connection with MySQL.</p>
  <p>P.S. I am successfully able to connect with same MySQL service outside Docker container by using (external MySQL port) <code>mysql -h 127.0.01 -u root -p -P 3306</code></p>
  <p><strong>Steps To Reproduce</strong></p>
  <ol>
  <li>Install Docker &amp; Docker Compose on Ubuntu 18.04</li>
  <li>Download the Docker Compose template: <code>curl -s https://raw.githubusercontent.com/markshust/docker-magento/master/lib/template | bash</code></li>
  <li>Replace with existing source code of your existing Magento instance: <code>cp -R ~/Sites/existing src</code></li>
  <li>Execute: <code>docker-compose -f docker-compose.yml up -d</code></li>
  <li>Copy files to container: <code>bin/copytocontainer --all</code></li>
  <li>Import existing database: <code>bin/mysql &lt; /var/www/magento243.sql</code></li>
  </ol>
  <p><strong>Expected Result</strong>
  Database should have been successfully imported</p>
  <p><strong>Actual Result</strong>
  ERROR 2002 (HY000): Can't connect to MySQL server on 'db' (115)</p>
  <p>P.S. Issue has already been raised here: <a href="https://github.com/markshust/docker-magento/issues/589" rel="nofollow noreferrer">https://github.com/markshust/docker-magento/issues/589</a></p>
  <p><strong>docker-compose.yml</strong></p>
  <pre><code>version: &quot;3&quot;
  
  services:
    app:
      image: markoshust/magento-nginx:1.18-5
      ports:
        - &quot;80:8000&quot;
        - &quot;443:8443&quot;
      depends_on:
        - &quot;db&quot;
      volumes: &amp;appvolumes
        - ~/.composer:/var/www/.composer:cached
        - ~/.ssh/id_rsa:/var/www/.ssh/id_rsa:cached
        - ~/.ssh/known_hosts:/var/www/.ssh/known_hosts:cached
        - appdata:/var/www/html
        - sockdata:/sock
        - ssldata:/etc/nginx/certs
      extra_hosts: &amp;appextrahosts
        ## M1 Mac support to fix Docker delay, see #566
        - &quot;app:172.17.0.1&quot;
        - &quot;phpfpm:172.17.0.1&quot;
        - &quot;db:172.17.0.1&quot;
        - &quot;redis:172.17.0.1&quot;
        - &quot;elasticsearch:172.17.0.1&quot;
        - &quot;rabbitmq:172.17.0.1&quot;
        ## Selenium support, replace &quot;magento.test&quot; with URL of your site
        - &quot;magento.test:172.17.0.1&quot;
  
    phpfpm:
      image: markoshust/magento-php:7.4-fpm-11
      volumes: *appvolumes
      extra_hosts: *appextrahosts
      env_file: env/phpfpm.env
  
    db:
      image: mariadb:10.4
      command: --max_allowed_packet=256M
      ports:
        - &quot;3306:3306&quot;
      env_file: env/db.env
      volumes:
        - dbdata:/var/lib/mysql
      extra_hosts: *appextrahosts
  
    redis:
      image: redis:5.0-alpine
      ports:
        - &quot;6379:6379&quot;
      extra_hosts: *appextrahosts
  
    elasticsearch:
      image: markoshust/magento-elasticsearch:7.9.3-1
      ports:
        - &quot;9200:9200&quot;
        - &quot;9300:9300&quot;
      environment:
        - &quot;discovery.type=single-node&quot;
        ## Set custom heap size to avoid memory errors
        - &quot;ES_JAVA_OPTS=-Xms1g -Xmx1g&quot;
        ## Avoid test failures due to small disks
        ## More info at https://github.com/markshust/docker-magento/issues/488
        - &quot;cluster.routing.allocation.disk.threshold_enabled=false&quot;
        - &quot;index.blocks.read_only_allow_delete&quot;
      extra_hosts: *appextrahosts
  
    rabbitmq:
      image: rabbitmq:3.8.22-management-alpine
      ports:
        - &quot;15672:15672&quot;
        - &quot;5672:5672&quot;
      volumes:
        - rabbitmqdata:/var/lib/rabbitmq
      environment:
        - RABBITMQ_VM_MEMORY_HIGH_WATERMARK=1GB
      extra_hosts: *appextrahosts
  
    mailcatcher:
      image: sj26/mailcatcher
      ports:
        - &quot;1080:1080&quot;
      extra_hosts: *appextrahosts
  
    ## Selenium support, uncomment to enable
    #selenium:
    #  image: selenium/standalone-chrome-debug:3.8.1
    #  ports:
    #    - &quot;5900:5900&quot;
    #  extra_hosts: *appextrahosts
  
  volumes:
    appdata:
    dbdata:
    rabbitmqdata:
    sockdata:
    ssldata:
  </code></pre>