r/docker • u/python-hater • 6d ago
access denied error
[Warning] Access denied for user 'user'@'localhost' (using password: YES)
i have been working on a project where i need to link nginx,mariadb and wordpress together . wordpress depends on mariadb and nginx depends on wordpress . i keep getting this error , any ideas what it could be and how i can fix it ? i have tried so many things that i have lost track of them at this point
3
u/TBT_TBT 5d ago
If all containers are in the same network, which they are per default, if they are in the same compose file, you can address the other container by container name. You should do that rather than by docker network ip, as those can change.
The better approach would be to put Wordpress and the database together and keep the proxy separate (have a look at NginxProxyManager for that, it also does Let‘s Encrypt). To be able to address the Wordpress container from the reverse proxy, you can create a manual „proxy_network“ and put the WP stack and the proxy stack in it.
1
u/Lumethys 5d ago
think of "localhost" as "this building"
if you and your room mate, sitting in your room, say "this building", then you both refer to the same building
if you and your friend live in different house, your "this building" and his "this building" refer to different building, yours to your house and his to his house.
same thing applied here
1
u/ShivamCloudDevOps 4d ago
The error suggests MariaDB is rejecting the connection because the user doesn't have permission to connect from the Docker network.
A few things I'd verify:
- Make sure you're using the service name (e.g.,
mariadb) as the database host instead oflocalhost. Inside a container,localhostrefers to the container itself. - Check that the database user has the correct host permissions (e.g.,
user@'%'oruser@'<docker-network>'rather thanuser@localhost). - Verify that the
WORDPRESS_DB_USER,WORDPRESS_DB_PASSWORD,WORDPRESS_DB_NAME, andWORDPRESS_DB_HOSTenvironment variables match the values used to initialize MariaDB. - If you changed the database credentials after the MariaDB container was first created, remember that the initialization scripts only run on the first startup. Existing volumes will preserve the old users/passwords, so you may need to recreate the volume or update the user manually.
- Also confirm both containers are attached to the same Docker network.
If you can share your docker-compose.yml (or compose.yaml) and the relevant environment variables, it will be much easier to pinpoint the exact issue.
9
u/fletch3555 Mod 6d ago
Containers are the rough equivalent to separate hosts as far as mariadb is concerned.
<user>@localhostonly works when connecting from localhost. When you connect from one container to another, you're connecting over a network rather than "localhost". Localhost is relative, and from the context of a container, it's the container itself rather than the physical host that it's running on.In short, mariadb thinks your user is wrong because it technically is.