d0001
d0001

Reputation: 2190

PhpMyadmin on Docker/MySQL on host

I'm trying to install/configure phpmyadmin using docker inside Ubuntu 14.04. I started like this:

docker run --name myadmin -d -e PMA_HOST=localhost -e PMA_PORT=3306 -p 8282:80 phpmyadmin/phpmyadmin

When I try to login I get the following error:

 #2002 - Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2 "No such file or directory") — The server is not responding (or the local server's socket is not correctly configured).

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

The MySQL server is installed directly in Ubuntu not in docker.

Any ideas?

Upvotes: 5

Views: 13284

Answers (5)

palto
palto

Reputation: 111

I faced the same issue and none of the previous answers worked for me. I found the solution in the GitHub issue 271, which maps the local socket into the docker container:

docker run --rm --name pma-socket -p 8080:80 -e PMA_SOCKET=/run/mysqld/mysqld.sock -v /run/mysqld/mysqld.sock:/run/mysqld/mysqld.sock phpmyadmin:latest

Upvotes: 1

Kavindu Chamiran
Kavindu Chamiran

Reputation: 11

For mac OS users, use host.docker.internal as the host address which docker will resolve to the host's IP address.

docker run --rm --name myadmin -it -e PMA_HOST=host.docker.internal -e PMA_PORT=3306 -p 8282:80 phpmyadmin/phpmyadmin

Upvotes: 1

cristian ayala
cristian ayala

Reputation: 125

This is what worked for me:

  1. Check you have your db up and running:
    "service mysql status" or "systemctl status mysqld"

(It should say active(running))

  1. Run phpMyAdmin in a container:
    docker run --name="phpMyAdmin-local" -itd -e PMA_HOST=$(ip route show | grep docker0 | awk '{print $9}') -p 8283:80 phpmyadmin/phpmyadmin
  1. Check container is up and running:
    docker ps -a 

(check phpMyAdmin-local status is up)

  1. Go to "localhost:8283" and check phpMyAdmin is there

  2. Let your db receive external requests:

Edit file as sudo:

MariaDb: nano /etc/mysql/mariadb.conf.d/50-server.cnf

MySQL: nano /etc/mysql/my.cnf

(nano is the text editor and can be changed)

and change this line:

bind-address            = 127.0.0.1

To this line: (note the "#")

# bind-address            = 127.0.0.1

(ctrl+x to exit, "y" to save it and "enter" to confirm)

  1. Give permision to users/user to connect from a different location (different from localhost):

Modify users and login to mysql/mariadb cli with root privileges:

    mysql -uroot -p -P3306 

(enter password after running command)

Use mysql database to edit users:

use mysql;

Give pribvileges to specific user: (can be different from root if you have other users):

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;

Then:

FLUSH PRIVILEGES;

and:

exit;

Restart mysql service:

service mysqld stop 
service mysqld start

And now you would be able to login to phpMyAdmin with the user and password you specify in prev. commands and mysql/mariadb would accept connections.

Upvotes: 2

Manoj Kumar1
Manoj Kumar1

Reputation: 15

Instead of connecting through socket file try to connect using IP (127.0.0.1) and for PMA port use your machine IP which you can get through ifconfig command.

Upvotes: -2

Sha7x
Sha7x

Reputation: 485

You cannot use localhost in your docker container.

docker run --rm --name myadmin -it -e PMA_HOST=172.17.0.1 -e PMA_PORT=3306 -p 8282:80 phpmyadmin/phpmyadmin

Where 172.17.0.1 is my host ip of the docker0 bridge.

Upvotes: 8

Related Questions