title: Symfony4 / Docker: SQLSTATE[HY000] [2002] Connection refused
body: <p>i have a problem with Symfony 4 and database connexion.
  I try to make migration with <code>php bin/console make:migration</code> but then i face the connection refused error. </p>
  
  <pre><code>In AbstractMySQLDriver.php line 113:
  
    An exception occurred in driver: SQLSTATE[HY000] [2002] Connection refused  
  
  
  In PDOConnection.php line 50:
  
    SQLSTATE[HY000] [2002] Connection refused  
  
  
  In PDOConnection.php line 46:
  
    SQLSTATE[HY000] [2002] Connection refused  
  </code></pre>
  
  <p>My .env file is like this. </p>
  
  <pre><code>###&gt; doctrine/doctrine-bundle ###
  # Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
  # For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
  # Configure your db driver and server_version in config/packages/doctrine.yaml
  DATABASE_URL=mysql://db_user:db_password@127.0.0.1:3306/db_name
  DATABASE_USER=sf4user
  DATABASE_PWD=sf4pwd
  DATABASE_NAME=sf4
  DATABASE_HOST=127.0.0.1
  DATABASE_PORT=3306
  ###&lt; doctrine/doctrine-bundle ###
  </code></pre>
  
  <p>And here is my packages/doctrine.yaml:</p>
  
  <pre><code>parameters:
      # Adds a fallback DATABASE_URL if the env var is not set.
      # This allows you to run cache:warmup even if your
      # environment variables are not available yet.
      # You should not need to change this value.
      env(DATABASE_URL): ''
  
      doctrine:
          dbal:
              # configure these for your database server
              driver: 'pdo_mysql'
              server_version: '5.7'
              charset: utf8mb4
              default_table_options:
                  charset: utf8mb4
                  collate: utf8mb4_unicode_ci
  
              host: '%env(DATABASE_HOST)%'
              user: '%env(DATABASE_USER)%'
              password: '%env(DATABASE_PWD)%'
              dbname: '%env(DATABASE_NAME)%'
              port: '%env(DATABASE_PORT)%'
  
              url: '%env(resolve:DATABASE_URL)%'
          orm:
              auto_generate_proxy_classes: '%kernel.debug%'
              naming_strategy: doctrine.orm.naming_strategy.underscore
              auto_mapping: true
              mappings:
                  App:
                      is_bundle: false
                      type: annotation
                      dir: '%kernel.project_dir%/src/Entity'
                      prefix: 'App\Entity'
                      alias: App
  </code></pre>
  
  <p>I understant that database URL is resolved on the basis of what i setted in .env file, but i cannot manage to make it  work and whenever i try to call a console method dealing with db i get the connection refused error.</p>
  
  <p>I build the project with a docker-compose.yml file:</p>
  
  <pre><code>version: '3'
  services:
      apache:
          build: .docker/apache
          container_name: sf4_apache
          ports:
            - 80:80
          volumes:
            - .docker/config/vhosts:/etc/apache2/sites-enabled
            - .:/home/wwwroot/sf4
          depends_on:
            - php
  
      mysql:
          image: mysql
          container_name: sf4_mysql
          volumes:
              - .docker/data/db:/var/lib/mysql
          command: ["--default-authentication-plugin=mysql_native_password"]
          ports:
              - "3306:3306"
          environment:
              MYSQL_ROOT_PASSWORD: root_pwd_test
              MYSQL_DATABASE: sf4
              MYSQL_USER: sf4user
              MYSQL_PASSWORD: sf4pwd
  
      php:
          build: .docker/php
          container_name: sf4_php
          volumes:
            - .:/home/wwwroot/sf4
          environment:
            - maildev_host=sf4_maildev
          depends_on:
            - maildev
            - mysql
  
      phpmyadmin:
          image: phpmyadmin/phpmyadmin
          container_name: sf4_phpmyadmin
          ports:
              - 8080:80
          links:
              - mysql
          environment:
              MYSQL_USERNAME: root
              MYSQL_ROOT_PASSWORD: root_pwd_test
              PMA_HOST: mysql
  </code></pre>
  
  <p>What could i be missing ?</p>