Continuous Drupal: Can't Connect to MariaDB



I was following this wonderful tutorial to get a docker container up and running but ran into some issues that I can’t seem to resolve.

Following the guide exactly, both of the containers start up, but when I go to the Drupal Installation it returns " Failed to connect to your database server. The server reports the following message: SQLSTATE[HY000] [2002] Connection refused." If I use docker-compose to enter bash on the database container I can access mysql from the command line, but from the drupal container, it’s inaccessible. Same goes for my Linux Host. I thought this might be because I had a MariaDB server running on my host and they were fighting for the same port so I stopped the one on my host and ran docker-compose again to build both but nothing changed.

What should I do? Thanks ahead of time.

EDIT: I wanted to also point that I have tried logging in like so from my drupal container mysql -h -u root -P 3306 -p and I get a different error ERROR 2003 (HY000): Can't connect to MySQL server on '' (111 "Connection refused"). I thought I might end up chasing down firewall configs for a while before I decided to try the wodby/docker4drupal images ( ). Those worked out perfectly, so this definately isn’t a firewall issue, but rather a networking issue between the containers. Really interested to see what it could be.


Well I think I finally found part of my answer, something that should definitely be mentioned in the guide since it’s targeted at new Docker users. For the Drupal Database configuration page, as per that guide you must change the ‘host’ under Advanced Options to ‘db’, which is the name of Docker Container running MariaDB. I realized that after reading the Drupal8 Docker Hub Image Notes.

However I’m getting a new fun error ERROR 1045 (28000): Access denied for user 'root'@'' (using password: YES) this also applies if I have another user created. Entering bash on mariadb container and using mysql provides the same result, access denied for both users. So now what?

The weird part is that this is now purely a Mariadb Image issue. If I use the default postgres example from the Docker Hub Page, it works fine. Here’s that for context:

version: ‘3.1’


image: drupal:8-apache
- 8080:80
- /var/www/html/modules
- /var/www/html/profiles
- /var/www/html/themes
# this takes advantage of the feature in Docker that a new anonymous
# volume (which is what we’re creating here) will be initialized with the
# existing content of the image at the same location
- /var/www/html/sites
restart: always

image: postgres:10
restart: always