Skip to content

Instantly share code, notes, and snippets.

@anilnabin25
Forked from poudelmadhav/phpmyadmin-in-docker.md
Last active May 15, 2024 08:47
Show Gist options
  • Save anilnabin25/316a4a3202a7c8fde14ccf237e35f8d4 to your computer and use it in GitHub Desktop.
Save anilnabin25/316a4a3202a7c8fde14ccf237e35f8d4 to your computer and use it in GitHub Desktop.
Run phpmyadmin in docker and connect to local mysql

Run phpmyadmin in docker

Find the ip address running this command:

ip addr show docker0 | grep inet

This will be the PMA_HOST in below steps. The PMA_HOST of local machine is like this: 172.17.0.1

Create a user

use this command to create a user for phpmyadmin login

CREATE USER 'phpmyadmin'@'%' IDENTIFIED BY 'P@ssw0rd123';
GRANT ALL PRIVILEGES ON *.* TO 'phpmyadmin'@'%' WITH GRANT OPTION;

Now, run phppmyadmin on docker.

You can achieve this in two ways. Choose only one approach.

Running with known host

To connect local mysql from phpmyadmin on docker. Run this:

docker run  --name phpmyadmin --rm -e PMA_HOST=172.17.0.1 -p 8080:80 phpmyadmin

Run in arbitrary mode

Run phpmyadmin in arbitrary mode

docker run --name phpmyadmin --rm -e PMA_ARBITRARY=1 -p 8080:80 phpmyadmin

Go to localhost:8080 to login to phpmyadmin

Debugging

Make sure the bind address of mysql is 0.0.0.0 and the MySQL suser host is %. Add or update /etc/mysql/my.cnf of MySQL configuration.

[mysqld]
bind-address = 0.0.0.0

You can confirm it from MySQL query also:

SHOW GLOBAL VARIABLES LIKE 'bind_address';
SELECT user, host from mysql.user;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment