WordPress : Error establishing a database connection

Hello there,
I installed WordPress from the official

I’m using Mac OS 11 and desktop Docker.
I followed the guide: https://docs.docker.com/compose/wordpress/
When I’m trying to connect to browser :
http://localhost:8000
Then, I have this error:
Error establishing a database connection

I don’t have error ?

What can I do from here?

➜  docker-wordpress docker --version
Docker version 20.10.2, build 2291f61
➜  docker-wordpress docker-compose up -d
docker-wordpress_db_1 is up-to-date
docker-wordpress_wordpress_1 is up-to-date
➜  docker-wordpress cat docker-compose.yml
services:
   db:
     image: mysql:5.7
     volumes:
       - db_data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: root
       MYSQL_DATABASE: wordpress
       MYSQL_USER: root
       MYSQL_PASSWORD: root

   wordpress:
     depends_on:
       - db
     image: wordpress:latest
     ports:
       - "8000:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress
       WORDPRESS_DB_NAME: wordpress
volumes:
    db_data: {}

In your db part, you set username and password as root, but down in wordpress, you say it can connect to mysql with wordpress/wordpress

you need to align that, also, remove the :3306 from db host

1 Like