Docker mysql_connect(): Can't connect

Bearing in mind I’m trying to run in a docker environment with php 5.4 due to Kohana PHP MVC being a framework which hasn’t been updated and is no longer going to be supported, get following error

mysql_connect(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)" ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(2) ["file":protected]=> string(64) "/var/www/html/modules/database/classes/kohana/database/mysql.php

my docker command is

  • Mount non-existing host directory into non-root container
  • Changing my project files doesn't change files inside the Docker machine
  • Access to the docker machine from Android app
  • Installing docker with devstack
  • How does docker run differ from running a command from a shell within the container
  • docker container running but not responding to localhost:49153
  • sudo docker run -d -p 8080:80 -p 3307:3306 -p 22:22  -v   "/home/me/public_html/project-folder:/var/www/html" ushios/lamp-ubuntu
    

    Am I missing something to make it work with the database, thanks

  • Unable to Make a development environment image for Docker opensource development
  • Trying to push an image to the docker registry
  • Executing a shell script within docker with RUN command
  • How to list images and their containers
  • Docker curl: (7) Failed to connect to localhost port 80: Connection refused
  • Cloud foundry scale
  • One Solution collect form web for “Docker mysql_connect(): Can't connect”

    It doesn’t look like your PHP settings are using the tcp connector.

    Can’t connect to local MySQL server through socket

    It seems to be using the ‘/var/run/mysqld/mysqld.sock’.
    The mysql_connect call defaults to using various PHP settings in absence of parameters.

    Check your setting in PHP and the mysql_connect() call itself.

    My guess is that you either need to:

    • Change the default settings
    • Add parameters to the mysql_connect call.

    As an aside, mysql_ is depreciated, you should use the mysqli_ set of calls if possible.

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