Reputation: 274
I have created a blog app with django and attached it to a mysql database stored on my local machine(localhost), which I manage through phpmyadmin.
However, I switched to an ubuntu 18.04 LTS (previously on a windows machine) and wanted to deploy my app with docker containers. I want to run mysql database in one container, and my blog app in another container, and have them communicate with each other (I am using docker-compose to achieve this).
Below is the DATABASES dictionary on my app:
And here is docker-compose.yml file.
After firing the docker-compose up command, I get this error:
It says '(2006, "Authentication plugin 'caching_sha2_password' cannot be loaded: dlopen(/usr/local/mysql/lib/plugin/caching_sha2_password.so: cannot open shared object file: No such file or diectory")'.
Upvotes: 0
Views: 258
Reputation: 8133
In the DB container, you are only setting password for root
user but using test
user. So you either need to set MYSQL_PASSWORD
env var. Or use root
user.
More on the env variables in mysql docker hub docs
My recommendation is to change db service definition to
services:
db:
image: mysql
enviroment:
MYSQL_RANDOM_ROOT_PASSWORD: 1
MYSQL_DATABASE: test
MYSQL_USER: test
MYSQL_PASSWORD: test
This encurages not to use root user, which is considered best practice.
What actually probably causes this errors is that you have wrong version of mysql. On mysql docker hub, you can see that the latest
tag (with is the implicit tag if you don't provide any), is the same as 8.0
. But a lot of apps is only compatible with the older 5.7
. To switch this, in your docker-compose add 5.7
tag:
services:
db:
image: mysql:5.7
(5.7 and 8.0 is actually only one major release apart, and 8.0 was released in 2017)
Upvotes: 1