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.

  • Docker Remote API does not list containers
  • Edit configuration file for running Docker instance of Kong
  • docker: Couldn't connect to Docker daemon
  • Docker: Development environments [closed]
  • Gradle Docker plugin connection timed out
  • How to edit files in stopped/not starting docker container
  • 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")
    

  • OpenShift 3.1 - Prevent Docker from caching curl resource
  • Assign static ip on docker 1.7
  • Connect to MySQL in a docker container (Vagrant on Windows/VirtualBox)
  • Docker build not using cache when running through ansible
  • Docker service create `n` replicas in `n-1` swarm nodes
  • Docker Remote API with Weave
  • One Solution collect form web for “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”)”

    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

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.