无法从docker容器

时间:2018-05-25 15:18:19

标签: mysql docker

按如下方式构建基于mysql的图像(Dockerfile):

FROM mysql:5.7

COPY somescripts* /docker-entrypoint-initdb.d/

然后执行它:

docker run --env="MYSQL_ROOT_PASSWORD=mypassword" -it theimagejustbuilt bash

但......

root@73857bf5744e:/# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

2 个答案:

答案 0 :(得分:0)

解决方案1。指定“127.0.0.1”作为主机而不是localhost,即mysql -h 127.0.0.1 -u root而不是mysql。请注意,如果省略主机(mysql -u root),MySQL客户端将隐式使用localhost。

解决方案2. 在/etc/mysql/my.cnf中,您应该会看到文件顶部附近的内容:

[client]
port          = 3306
socket        = /var/run/mysqld/mysqld.sock
Change socket to the location of your MemSQL socket file. By default, this is /var/lib/memsql/data/memsql.sock.

答案 1 :(得分:0)

原来我通过以下命令意外地覆盖了入口点:

docker run --env="MYSQL_ROOT_PASSWORD=mypassword" -it theimagejustbuilt bash

最后不需要bash关键字,因为它会覆盖默认入口点,因此无法连接到mysql服务。

相关问题