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

  • local files missing from docker-machine container
  • ERROR: Service 'redis' failed to build. When building redis image by docker-compose
  • Docker + SSH + Git Clone Isssue
  • Authorization Not working with identityserver4 when using docker
  • Docker do not release ports after stop and remove all container
  • Does docker stores all its files as “memory image”, as part of image, not disk file?
  • 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

  • What are mix and match attacks? (Docker - snapshot key)
  • Dockerfile COPY wildcard to only match files, not folders
  • How to access tomcat docker container running in VMWare workstation?
  • docker run command change to .yaml file
  • Access docker-machine VM ports without port forwarding
  • Docker - Unable to pull images - certificate issues?
  • 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.