Reputation: 21668
I am trying to play with Docker. This is my dockerfile:
FROM mysql:latest
ENV MYSQL_ROOT_PASSWORD 123
ENV MYSQL_DATABASE users
ENV MYSQL_USER admin
ENV MYSQL_PASSWORD 1234
ADD setup.sql /docker-entrypoint-initdb.d
EXPOSE 3306
CMD tail -f /dev/null
And the following is my attempt to access to mysql from the container.
root@76757566f93a:/# mysql -uroot -p123 mysql: [Warning] Using a password on the command line interface can be insecure. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Finally, .. this is a Makefile I use to run all docker commands:
container = db
image-name = senso
run:
docker run --name $(container) -d $(image-name)
bash:
docker exec -it $(container) /bin/bash
build:
docker build -t $(image-name) .
I've also tried to run mysql -v
to check if mysql is ok inside the container and I think is not.
root@76757566f93a:/# mysql -v ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Upvotes: 1
Views: 1145
Reputation: 60094
The reason is mysql
process is not running, as you override the CMD
in your Dockerfile, as the base CMD
starting Mysql
process.
CMD tail -f /dev/null
Remove the CMD
from the Dockerfile.
You do not need to replace as the base image will do care of it, but if want to replace then use the following
ENTRYPOINT ["/entrypoint.sh"]
CMD ["mysqld"]
Also ADD setup.sql /docker-entrypoint-initdb.d
only possible when MySQL process is running with offical entrypoint script.
Upvotes: 2