Reputation: 493
I try to run my app with DB on single AWS EC2 (Ubuntu), and decided to try with docker.
I have very basic setup:
docker-compose.yml
version: '3.3'
services:
db:
image: library/mysql:8.0.20
restart: always
env_file:
- ./.env
ports:
# <Port exposed> : < MySQL Port running inside container>
- '3306:3306'
expose:
# Opens port 3306 on the container
- '3306'
# Where our data will be persisted
volumes:
- my-db:/var/lib/mysql
# Names our volume
volumes:
my-db:
And with following .env
content:
MYSQL_DATABASE=db
MYSQL_USER=user
MYSQL_PASSWORD=password
MYSQL_ROOT_PASSWORD=password
MYSQL_HOST=localhost
I run it in detached mode with docker-compose:
sudo docker-compose up -d
And after when I try to connect from the host it fails, but what the more interesting, I'm not even able to connect from the container using following command:
sudo docker exec -it db_1 mysql db -P 3306 --protocol=tcp -u root -h localhost -p
I got the next response:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
There is nothing appearing in docker logs, and I'm out of ideas what possibly can be wrong.
Please help me if you have faced with this issue before or know what I'm missing!
Upvotes: 0
Views: 1623
Reputation: 493
Investigated issue with @nub8er, we found out that it was wrongly initially configured MySQL image. It looks like on the first run I've killed container before it has properly initialised, and for all next tried I was not able to connect properly.
Now everything works correctly, thank you @num8er for the help on investigation!
Upvotes: 1