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:

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

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.

image of PHPMyAdmin login screen

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.

image of creating a PHPMyAdmin configuration database

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:

docker run -d --name phpmyadmin -e -e PMA_PORT=33060 -p 8080:80 phpmyadmin

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 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:

docker run -d --name phpmyadmin --link my_mysql_container:db -p 8080:80 phpmyadmin

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:

docker network create phpmyadmin
docker network connect phpmyadmin mysql_container_name --ip
docker network connect phpmyadmin phpmyadmin_container_name

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

docker run -d --name phpmyadmin --network phpmyadmin -p 8080:80 phpmyadmin

Now PHPMyAdmin will be able to reach the MySQL container via the shared network. Set the PMA_HOST environment variable to 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:

version: "3"

    image: phpmyadmin:latest
        - 8080:80
        - PMA_ARBITRARY=1
    restart: unless-stopped

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

version: "3"

    image: mysql:latest
      - 3306
      - mysql:/var/lib/mysql
    restart: unless-stopped
    image: phpmyadmin:latest
      - 8080:80
      - PMA_HOST: mysql
    restart: unless-stopped

  - mysql

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/

docker run -d 
    --name phpmyadmin 
    -p 8080:80 
    -v my-config-file.php:/etc/phpmyadmin/

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.

docker run -d --name phpmyadmin -e PMA_HOST_FILE=/run/secrets/pma_host -p 8080:80 phpmyadmin


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.

Profile Photo for James Walker James Walker
James Walker is a contributor to How-To Geek DevOps. He is the founder of Heron Web, a UK-based digital agency providing bespoke software development services to SMEs. He has experience managing complete end-to-end web development workflows, using technologies including Linux, GitLab, Docker, and Kubernetes.
Read Full Bio »