title: wp-cli in Docker fetches wrong database login credentials from wp-config
body: <p>Here is my <code>docker-compose.yml</code> file:</p>
  <pre class="lang-yaml prettyprint-override"><code>version: '3.9'
  
  services:
    db:
      image: mysql:5.7
      restart: always
      command: [
          '--disable-partition-engine-check',
          '--default_authentication_plugin=mysql_native_password',
          '--character-set-server=utf8mb4',
          '--collation-server=utf8mb4_unicode_ci',
          '--max_allowed_packet=100M'
      ]
      volumes:
        - ./db_data:/var/lib/mysql
      environment:
        MYSQL_DATABASE: wordpress
        MYSQL_ROOT_PASSWORD: pswd4!
  
  
    pma:
      image: phpmyadmin/phpmyadmin
      environment:
        PMA_HOST: db
        PMA_PORT: 3306
        MYSQL_ROOT_PASSWORD: pswd4!
        UPLOAD_LIMIT: 1G
      ports:
        - 8080:80
      depends_on:
        - db
  
    wp:
      image: wordpress:php8.0
      ports:
        - 80:80
      volumes:
        - ./config/php.conf.ini:/usr/local/etc/php/conf.d/conf.ini
        - ./:/var/www/html
      environment:
        WORDPRESS_DB_HOST: db
        WORDPRESS_DB_NAME: wordpress
        WORDPRESS_DB_USER: root
        WORDPRESS_DB_PASSWORD: pswd4!
        WORDPRESS_DEBUG: 1
  
      depends_on:
        - db
      links:
        - db:mysql
      hostname: test.localhost
  
    wpcli:
      image: wordpress:cli-php8.0
      volumes_from:
        - wp
      depends_on:
        - db
        - wp
      links:
        - db:mysql
      entrypoint: wp
      command: &quot;--info&quot;
  
  
  
  volumes:
    db_data:
  </code></pre>
  <p>When I try to use <code>wp-cli</code> in Docker (e.g. <code>docker-compose run --rm wpcli plugin list</code>), it gets an error that it cannot connect to the database:</p>
  <pre><code>Error: `Access denied for user 'username_here'@'192.168.32.5' (using password: YES)`
  Error establishing a database connection
  This either means that the username and password information in your `wp-config.php` file is incorrect or we can’t contact the database server at `mysql`. This could mean your host’s database server is down.
  
  Are you sure you have the correct username and password?
  Are you sure you have typed the correct hostname?
  Are you sure the database server is running?
  
  If you’re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the WordPress Support Forums. `Access denied for user 'username_here'@'192.168.32.5' (using password: YES)
  `
  </code></pre>
  <p>It looks like wp-cli is seeing bad database credentials (<code>username_here</code> instead of <code>root</code>)</p>
  <p>Result of executing <code>docker-compose run --rm wpcli config list</code> command:
  <a href="https://i.stack.imgur.com/4fCwP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4fCwP.png" alt="enter image description here" /></a></p>
  <p>What could be wrong? I've searched all over the internet, lost several hours and still haven't found the cause of the problem.</p>