Skip to content

Instantly share code, notes, and snippets.

@poudelmadhav
Last active July 15, 2025 10:42
Show Gist options
  • Save poudelmadhav/488924f431f1f74717dddf5e70579e04 to your computer and use it in GitHub Desktop.
Save poudelmadhav/488924f431f1f74717dddf5e70579e04 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

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

Debugging with mysql

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

Restart mysql

sudo systemctl restart mysql

Allow mysql user's host from everywhere:

UPDATE mysql.user SET Host='%' WHERE Host='localhost' AND User='username';
FLUSH PRIVILEGES;

You can confirm it from MySQL query also:

SHOW GLOBAL VARIABLES LIKE 'bind_address';
SELECT user, host from mysql.user;

Debugging with docker

If you have not installed docker or have permissions error running docker, follow these steps:

Install docker:

sudo snap install docker

Create new group docker and add logged in user to there:

sudo groupadd docker
sudo usermod -aG docker $USER

Log in as new group to confirm if you have sufficient permission:

newgrp docker

Change the docker.sock file permission:

sudo chown root:docker /var/run/docker.sock

References

@poudelmadhav
Copy link
Author

poudelmadhav commented Jul 8, 2025

If you want to run phpmyadmin and connect another docker mysql, use following command

docker run --rm \
  --name phpmyadmin \
  --link another-docker:db \
  -e PMA_HOST=db \
  -e PMA_PORT=3306 \
  -p 8080:80 \
  phpmyadmin

OR, with new approach since --link is deprecated.

First, create a network, and run both containers in the same network passing the flag --network your-network

To create a network:

docker create network your-network

Now, run both another docker and phpmyadmin in same network. Note, you need to specify another-docker in PMA_HOST.

docker run --rm \
  --name phpmyadmin \
  --network your-network \
  -e PMA_HOST=another-docker \
  -e PMA_PORT=3306 \
  -p 8080:80 \
  phpmyadmin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment