I am having some issues connecting to the mysql docker container that I have launched with docker-compose. This is a long post (sorry!).
Here is my docker-compose.ym
editd docker-compose.yaml is not work when you already start that container,
so I support this way:
1: chack you db containers that already exist
docker ps
CONTAINER ID NAMES PORTS STATUS
1cbfe602466a mysql5.7 Exited (0) About an hour ago
2: if the container has been stared,then stop it and rm
docker stop 1cbfe602466a //(mysql5.7)
docker rm 1cbfe602466a
3: now you can Restart mysql container,
docker-compose.yaml //(Pay attention to formatting your code)
mysql5.7:
container_name: mysql5.7
image: mysql:5.7
restart: always
environment:
- MYSQL_ROOT_PASSWORD=root
ports:
- 3306:3306
4: run commend:
docker-compose up -d mysql5.7
5: you are success! you can check it into container .
docker exec -it mysql5.7 /bin/bash
root@1719480b6716:/# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.29-log MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>