Contents
docker-mysql-phpadmin is a small Compose file that starts MySQL 8.0 and phpMyAdmin together. There is no custom image and no script, only two services and one volume.
The idea worth taking from it is how the web interface is pointed at the database. That takes three environment variables, and one of them needs more care than the other two.
A service name is an address
phpmyadmin:
depends_on:
- mysql
image: phpmyadmin/phpmyadmin
environment:
PMA_HOST: mysql
PMA_PORT: 3306
PMA_ARBITRARY: 1
ports:
- "8181:80"PMA_HOST is mysql. That is not an address from the internet. It is the name of the first service in the file. The file has no networks: block, so Compose creates a default network for the project, and each service on it can be reached by its service name.
Inside the phpMyAdmin container, mysql therefore means the MySQL container. localhost would mean phpMyAdmin itself, which is the usual first mistake. The readme says the same thing: the server is mysql, the service name.
The three settings
PMA_HOST says where to connect. PMA_PORT is 3306, which is already MySQL's standard port, so that line changes nothing and could be dropped.
PMA_ARBITRARY: 1 is the interesting one. With it on, the login form has a server field, pre-filled with mysql as the readme notes. You can type any host the container can reach. With it off, login is tied to PMA_HOST.
Two accounts, two views
The MySQL service creates two logins from its environment, and the readme lists both for phpMyAdmin.
| Login | Password | What it can reach |
|---|---|---|
root | root | every database on the server |
admin | password | the mydb database |
MYSQL_ROOT_PASSWORD sets the first. MYSQL_USER and MYSQL_PASSWORD create the second, and MYSQL_DATABASE creates mydb. The image gives the extra user rights on that one database. Use admin for everyday work and keep root for when you need it.
Only the interface is published
Only the phpmyadmin service has a ports: entry. MySQL's port 3306 is reachable from other containers in the project but not from the host. The readme shows how to change that: add "3306:3306" under the mysql service.
depends_on controls start order only. There is no health check, so the phpMyAdmin container can start before MySQL accepts connections. That does no harm here, because phpMyAdmin opens a connection when you log in, not when it starts. An application container using the same pattern would need to retry or wait.
What to change before real use
- Credentials.
root/rootandadmin/passwordsit in plain text in the file. - The login page.
"8181:80"has no host address, so it listens on every interface, over plain HTTP. Combined withPMA_ARBITRARY: 1, anyone who can reach that port gets a form where they can name any host the container can see. Delete the setting, and publish as"127.0.0.1:8181:80". - Image tags.
mysql:8.0is pinned to a release series, butphpmyadmin/phpmyadminhas no tag, so it moves wheneverlatestdoes.
The same two services appear inside a larger stack in Named Volumes and Bind Mounts in a Local WordPress Stack.
When this fits
This is a good shape for local development: one command, a UI for looking at tables, and a database that is not exposed on the host. I would not put it anywhere another machine can reach port 8181. If I kept one change from the list above, it would be removing PMA_ARBITRARY, since it costs nothing and closes the widest gap.
Found this useful? Share it with your team.