Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker alpine image : ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2 "No such file or directory")

Hi there is a public alpine mysql image for docker. https://hub.docker.com/r/wangxian/alpine-mysql/

I wanted to run mysql in it.

I am getting this error when I execute the mysql command after docker run command:

docker run -i -t wangxian/alpine-mysql sh
/app # mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2 "No such file or directory")

Well then I installed everything from scratch. I made a new image of alpine and then I installed these things:

apt add mysql mysql-client

And then I again typed mysql and got same error. This looks like a common error, it happens on all alpine images because this was a fresh install of alpine.

Any solutions ?

Edit: When I do docker run -i -t wangxian/alpine-mysql

2016-08-17 12:51:41 140215609339688 [Note] Plugin 'FEEDBACK' is disabled.
2016-08-17 12:51:41 140215609339688 [Note] Server socket created on IP: '::'.
2016-08-17 12:51:41 140215609339688 [Note] /usr/bin/mysqld: ready for connections.
Version: '10.1.11-MariaDB-log'  socket: '/run/mysqld/mysqld.sock'  port: 3306  MariaDB Server

And then I opened new tab in command line while keeping that tab open, I again get the same error:

docker run -i -t wangxian/alpine-mysql sh
/app # mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2 "No such file or directory")
like image 704
user1735921 Avatar asked Nov 09 '22 10:11

user1735921


1 Answers

Thats not really how the image you used works. On the Docker Hub page you can see how it is supposed to be run. It has a startup script which is not called when you pass the "sh" command on run, so mysql is not running. When you run the image without any commands it starts mysql and sets some initial values for username/password. Then you can enter the running container with docker exec or can link other container to it

like image 122
kgorskowski Avatar answered Nov 14 '22 23:11

kgorskowski