Ecommerce Shopify WordPress Discussion

WordPress & Docker Compose – "Error establishing a database connection" / "Database Error" using wp-config.php

I'm working on Debian based VM. I'v connected to it via SSH. I'm doing a simple compose projcet, but my localhost throws Error establishing a database connection My Dockerfile with wordpress image. I use COPY to pass configs from file to my container FROM wordpress:latest COPY --chown=www-data:www-data wp-config.php /var/www/html/ My wp-config.php <?php define( 'DB_NAME', 'wordpress' ); define( 'DB_USER', 'wordpress' ); define( 'DB_PASSWORD', 'wordpress' ); define( 'DB_HOST', 'my-awesome-database:3306' ); define( 'DB_CHARSET', 'utf8' ); define( 'DB_COLLATE', '' ); define( 'AUTH_KEY', 'put your unique phrase here' ); define( 'SECURE_AUTH_KEY', 'put your unique phrase here' ); define( 'LOGGED_IN_KEY', 'put your unique phrase here' ); define( 'NONCE_KEY', 'put your unique phrase here' ); define( 'AUTH_SALT', 'put your unique phrase here' ); define( 'SECURE_AUTH_SALT', 'put your unique phrase here' ); define( 'LOGGED_IN_SALT', 'put your unique phrase here' ); define( 'NONCE_SALT', 'put your unique phrase here' ); $table_prefix = 'wp_'; define( 'WP_DEBUG', false ); if ( ! defined( 'ABSPATH' ) ) { define( 'ABSPATH', __DIR__ . '/' ); } require_once ABSPATH . 'wp-settings.php'; My docker-compose.yml" version: "3" services: my-awesome-database: # My database service image: mysql:5.7 container_name: my-awesome-database environment: - MYSQL_ROOT_PASSWORD=somewordpress # Mandatory env - MYSQL_DATABASE=wordpress - MYSQL_USER=wordpress - MYSQL_PASSWORD=wordpress networks: # Adding two containers to one bridge net to communicate each other - my-awesome-network restart: unless-stopped command: '--default-authentication-plugin=mysql_native_password' volumes: # To save database configs after restart container - mysql:/var/lib/mysql my-awesome-wordpress: build: . # Build image from Dockerfile container_name: my-awesome-wordpress networks: - my-awesome-network restart: unless-stopped volumes: # Saving wp-config.php file, if reboot container - wordpress:/var/www/html depends_on: - my-awesome-database ports: - "8080:80" networks: my-awesome-network: driver: bridge volumes: wordpress: driver: local mysql: driver: local I did all like in official docker sample here but it doesn't works Wordpress says that this error could happened becouse of wrong DB vars. So, I assume, something wrong with wp-config.php or with evironments in compose file, but don't understand what actually
I feel myself really dumb. The solution was just clear volumes using docker volume prune # Make sure you don't have important data in volumes! Nothing to change in code just recreate volumes Why is this issue possible? I guess, becouse of changing docker-compose.yml and wg-config.php. After changes docker used OLD data and that's why I couldn't connect to my database. Thanks all, who spend their time!

February 26, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.