I'm using below command to run the mysql docker container.
docker container run -it --name mysql-test -e MYSQL_ROOT_PASSWORD=secret mysql bash
Then I tried to connect to mysql inside docker container using below command.
mysql -uroot -psecret
It gives me below error.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
If I do below then sometimes it works but not all time.
touch /var/run/mysqld/mysqld.sock
Then I tried to run the container in detach mode but it also gave me the same error.
docker container run -d -p 3306:3306 --name mysql-test -e MYSQL_ROOT_PASSWORD=secret mysql
docker exec -it mysql-test bash
mysql -uroot -p
What am I doing wrong here?