title: An exception occurred in driver: SQLSTATE[HY000] [2002] Connection refused
body: <p>I have a problem with docker and symfony to access mysql.</p>
  
  <p>To try to query mysql by connecting to the php container:</p>
  
  <blockquote>
    <p>docker exec -it symfony_php bash</p>
  </blockquote>
  
  <p>Then I execute the following command:</p>
  
  <blockquote>
    <p>bin/console doctrine:database:create</p>
  </blockquote>
  
  <p>This is where I get the following error message:</p>
  
  <blockquote>
    <p>An exception occurred in driver: SQLSTATE [HY000] [2002] Connection refused</p>
  </blockquote>
  
  <p>Here is the code of my "docker-compose.yml":</p>
  
  <pre><code>version: '3'
  services:
      apache:
          container_name: symfony_apache
          build: .docker/apache
          ports:
              - "80:80"
          volumes:
              - .docker/config/vhosts:/etc/apache2/sites-enabled
              - .:/home/www/symfony
          depends_on:
            - php
  
      mysql:
          container_name: symfony_mysql
          image: mysql
          ports:
              - "3306:3306"   
          volumes:
              - .docker/data/db:/var/lib/mysql
          environment:
              MYSQL_ROOT_PASSWORD: root
              MYSQL_DATABASE: sf4
              MYSQL_USER: sf4
              MYSQL_PASSWORD: sf4
  
      php:
          container_name: symfony_php
          build: .docker/php
          volumes:
              - .:/home/www/symfony
          depends_on:
              - mysql 
  
      phpmyadmin:
          container_name: symfony_phpmyadmin
          image: phpmyadmin/phpmyadmin
          ports:
              - "8080:80"
          environment:
              PMA_HOST: mysql
              PMA_PORT: 3306
          links:
              - mysql
  </code></pre>
  
  <p>Here is the code of my .env:</p>
  
  <blockquote>
    <p>DATABASE_URL=mysql://root:root@127.0.0.1:3306/s4</p>
  </blockquote>