I have a really simple application in dotnet core 2.1 which talks to a MySQL database. The application uses Entity Framework like this:
var connectionString = Configuration.GetConnectionString("DatabaseConnection");
services.AddDbContext<ChtrDbContext>(options => options.UseMySql(connectionString));
Where the connectionString looks like this:
"DatabaseConnection": "Server=db;port=3306;Database=chtr;userid=dbuser;Password=dbuserpassword"
The application is dockerized and I use docker-compose up --build to start the environment.
When I navigate to localhost:8080/graphql, which is my GraphiQL endpoint and I try to do a simple query against the database, I'm unable to log in. This is the log file:
Access denied for user 'dbuser'@'172.19.0.3' (using password: YES)
chtr.server_1 | at MySqlConnector.Core.ServerSession.ConnectAsync(ConnectionSettings cs, ILoadBalancer loadBalancer, IOBehavior ioBehavior, CancellationToken cancellationToken) in C:\projects\mysqlconnector\src\MySqlConnector\Core\ServerSession.cs:line 360
It says that dbuser which is the configured user, doesnt have access rights to my database.
Running docker ps which lists all my containers I can see that the mysql container is running. Then again I run docker inspect chtrserver_db_1 which is the container name. Scrolling down to the Config section of this json file gives me the following:
"Env": [
"MYSQL_RANDOM_ROOT_PASSWORD=1",
"MYSQL_DATABASE=chtr",
"MYSQL_USER=dbuser",
"MYSQL_PASSWORD=dbuserpassword",
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"GOSU_VERSION=1.7",
"MYSQL_MAJOR=5.7",
"MYSQL_VERSION=5.7.26-1debian9"
],
Alright, so I've confirmed that the docker container is running and the credentials specified in the connecting string is equal to what's configured within the container. How come that I'm unable to log in still?
The docker-compose.yml file looks like this:
version: '3.0'
services:
db:
image: mysql:5.7
environment:
MYSQL_RANDOM_ROOT_PASSWORD: 1
MYSQL_DATABASE: chtr
MYSQL_USER: dbuser
MYSQL_PASSWORD: dbuserpassword
volumes:
- dbdata:/var/lib/mysql
- ./Scripts:/docker-entrypoint-Dataseed.d
restart: always
chtr.server:
depends_on:
- db
image: trebias/chtr.server
build:
context: .
ports:
- "8080:80"
volumes:
dbdata:
Any suggestions on how to move forward?