I am just getting into docker and have a simple mysql 5.5 set up using the official image. Here are my relevant files.
#Dockerfile
FROM mysql:5.5
ENV MYSQL_ROOT_PASSWORD password
#docker-compose.yml
db:
build: .
Now I run docker-compose build followed by docker-compose up
which gives the following output
db_1 | 150828 14:04:17 [Note] mysqld: ready for connections.
db_1 | Version: '5.5.45' socket: '/tmp/mysql.sock' port: 3306 MySQL Community Server (GPL)
Now in another terminal I run docker-compose run db bash and get into the bash shell. But in this shell if I try to connect the mysql client I get an error.
root@94a43b1f5be0:/# mysql -u root -p
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
The same thing works with plain old docker. Example(Using the same Docker file):
docker build -t my-new-image .
docker run --name my-new-image-container -d my-new-image
docker exec -it my-new-image-container bash
root@8408282d162f:/# mysql -u root -p
mysql>
What am I doing wrong with docker-compose. How can I connect to my running mysql container and fire some queries. Any help would be appreciated.