PHPMyAdmin is a popular administration interface for MySQL and MariaDB databases. It lets you interact with your schemas, tables, and data using a web browser.

The project has an official Docker image which simplifies deployment in containerized environments. Here’s how to use the image to quickly get a new PHPMyAdmin instance running.

Basic Usage

The simplest installation lets a PHPMyAdmin container connect to any accessible database server:

This command starts PHPMyAdmin on port 8080. Visit localhost:8080 in your browser to see the login screen. The presence of the PMA_ARBITRARY environment variable results in a server connection form being displayed. Specify the host and user credentials of your MySQL or MariaDB database to login.

When you’re using this method, you’ll normally see a PHPMyAdmin warning that “some extended features have been deactivated.” This occurs when the server you’re connected to has no database called phpmyadmin. PHPMyAdmin uses this schema to store its own configuration data.

Follow the warning’s link to “Create a database” to complete the installation. Your user account will need permission to create new databases on the server.

Presetting a Server

As an alternative to allowing arbitrary access, you can start the PHPMyAdmin container with a preconfigured server connection. Supply the PMA_HOST and PMA_PORT environment variables instead of PMA_ARBITRARY:

PMA_PORT is optional. It will use the MySQL default of 3306 when no value is supplied.

Starting the container with these variables will constrain PHPMyAdmin to working with the mysql.example.com server. You’ll be prompted for a username and password on the login screen but you won’t need to supply a hostname.

PHPMyAdmin can also be configured to present multiple server options. Supply PMA_HOSTS and PMA_PORTS as comma-separated lists of connections to enable this functionality.

Using a MySQL Docker Container

Another common use case is connecting to a MySQL or MariaDB server running in a separate Docker container. You can either expose the database server on a port or connect both containers to a shared Docker network. In either case, use the PMA_HOST and PMA_PORT environment variables will instruct PHPMyAdmin how to connect to the server.

Legacy Docker links are also supported:

This command lets you connect PHPMyAdmin to the my_mysql_container container without manually setting up networking links. This functionality is deprecated in Docker though so switching to the network commands is preferable:

As an alternative, you can start PHPMyAdmin with a preconfigured network connection using Docker’s –network flag:

Now PHPMyAdmin will be able to reach the MySQL container via the shared network. Set the PMA_HOST environment variable to 172.17.0.1 when you start the container.

Simplifying Deployment With Docker Compose

Writing a Docker Compose file simplifies non-trivial deployments. You can bring up a new PHPMyAdmin container in a repeatable fashion using the docker-compose up -d command.

Here’s a docker-compose.yml for PHPMyAdmin in arbitrary connection mode:

Docker Compose also helps you create a stack with a fresh MySQL database installation and a PHPMyAdmin container:

Run docker-compose up -d to bring up MySQL with a fully networked PHPMyAdmin container. PHPMyAdmin’s PMA_HOST variable is set to mysql, referencing the MySQL service name. Docker Compose automatically sets hostnames to match service names, allowing PHPMyAdmin to connect to MySQL using the shared network.

Configuring the Installation

THe PHPMyAdmin Docker image supports a user-supplied configuration file that you can inject via a Docker volume. The path is /etc/phpmyadmin/config.user.inc.php:

You can add any of the configuration variables supported by PHPMyAdmin.

The image also supports environment variables for many common settings. These include MEMORY_LIMIT, UPLOAD_LIMIT and MAX_EXECUTION_TIME, each of which correspond to PHP INI values that might need to be adjusted if you’re using long-running or complicated queries.

Sensitive values, such as PMA_HOST, PMA_PASSWORD, and MYSQL_ROOT_PASSWORD, can be injected using Docker secrets instead of plain environment variables. Append _FILE to the variable’s name, then set the value to a path inside the container that provides the actual value.

Summary

PHPMyAdmin is one of the most popular and best known MySQL administration utilities. Bare-metal installation adds several dependencies to your system, bundling Apache and PHP alongside the app’s source code.

Installing PHPMyAdmin in Docker gives you an isolated environment that can be created, replaced, and deleted using a handful of Docker CLI commands. The official image can connect to any MySQL server that’s accessible from your host, including databases running in other Docker containers.

More detailed guidance on running and using PHPMyAdmin can be found in the official documentation. It’s particularly important to review the security guide so you don’t unintentionally leave your database at risk of external attack. You should also consider Docker security best practices when deploying PHPMyAdmin inside a container that’s exposed to the outside world.