(It's probably a dumb question due to my limited knowledge with Docker or mysql administration, but since I spent a whole evening on this issue, I dare to ask it.)
In a nutshell
我想在docker容器中运行mysql,并从主机连接到它.到目前为止,我取得的最好成绩是:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
More details
我使用的是以下Dockerfile
个:
FROM ubuntu:14.04.3
RUN apt-get update && apt-get install -y mysql-server
# Ensure we won't bind to localhost only
RUN grep -v bind-address /etc/mysql/my.cnf > temp.txt \
&& mv temp.txt /etc/mysql/my.cnf
# It doesn't seem needed since I'll use -p, but it can't hurt
EXPOSE 3306
CMD /etc/init.d/mysql start && tail -F /var/log/mysql.log
在这个文件所在的目录中,我可以成功地构建映像并使用以下工具运行它:
> docker build -t my-image .
> docker run -d -p 12345:3306 my-image
当我附加到图像上时,它似乎工作得很好:
# from the host
> docker exec -it <my_image_name> bash
#inside of the container now
$ mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
[...]
然而,我没有从主持人那里获得那么多成功:
> mysql -P 12345 -uroot
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Even more details
- 我看到有一个问题是哪个looks like mine.然而,这是不一样的(而且它也没有任何答案)
服务器主机名(绑定地址):"0.0.0.0";港口:3306