Search

How to Set up phpMyAdmin using Docker Compose

Share it

Configuring phpMyAdmin with Docker Compose

For the past couple of decades, phpMyAdmin has served as the primary solution for MySQL and MariaDB database management.

This tool, built in PHP, is open-source and free, providing users with a web-based interface for a range of database tasks. These include creating, modifying, and deleting databases, managing tables, executing SQL statements, and controlling users and permissions.

However, setting up phpMyAdmin traditionally requires PHP installation and php-fpm support configuration with your chosen web server, such as NGINX or Apache. Fortunately, Docker simplifies this operation, enabling a swift phpMyAdmin setup within minutes. This allows you to focus on database management without the initial setup hassle.

This guide will detail how to establish a phpMyAdmin container using Docker Compose, ensuring a successful connection with your MySQL or MariaDB database. Let’s begin!

Prerequisites

Prior to installation, ensure Docker is set up on your system. If Docker is not installed, various guides are available to help you quickly install it, specific to Ubuntu 24.04, Debian 12, Arch, Alma/Rocky, Fedora, Linux Mint 22, Pop!_OS 22.04, or Raspberry Pi OS.

Docker Compose is another essential component. Recent Docker versions include Docker Compose via the “docker-compose-plugin” package. However, if you prefer a separate installation, utilize the provided commands. Remember to use “docker-compose” instead of “docker compose” when executing the tool.

sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-linux-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

Running phpMyAdmin and MySQL Containers Simultaneously

One common scenario involves initiating MySQL alongside a phpMyAdmin container for database administration. To start, create a project directory and switch to it, ensuring all subsequent commands are executed from this location.

mkdir phpmyadmin
cd phpmyadmin

Create a file named “docker-compose.yml” to define services and volumes for phpMyAdmin and MySQL.

nano docker-compose.yaml
services:
  phpmyadmin:
    image: phpmyadmin:latest
    container_name: phpmyadmin
    ports:
      - 8080:80
    environment:
      - PMA_ARBITRARY=0
      - PMA_HOST=db
    restart: unless-stopped
    depends_on:
      - db
  db:
    image: mysql:latest
    container_name: mysql
    ports:
      - 3306:3306
    environment:
      MYSQL_ROOT_PASSWORD: mypassword
    restart: unless-stopped
    volumes:
      - dbdata:/var/lib/mysql

volumes:
  dbdata:

Initiate the containers with the command:

docker compose up -d

Following successful deployment, access phpMyAdmin via “http://localhost:8080” in your browser to login.

Log in using the MySQL root password specified in your Docker Compose file. Your phpMyAdmin should connect to the MySQL instance seamlessly.

Connecting phpMyAdmin to Locally Installed MySQL

If MySQL/MariaDB is locally installed instead of within a Docker container, additional configurations are required to link phpMyAdmin to the local MySQL.

Modify the “docker-compose.yml” file for phpMyAdmin:

services:
  phpmyadmin:
    image: phpmyadmin:latest
    container_name: phpmyadmin
    ports:
      - 8080:80
    extra_hosts:
      - "host.docker.internal:host-gateway"
    environment:
      - PMA_ARBITRARY=0
      - PMA_HOST=host.docker.internal
    restart: unless-stopped

Adjust the “bind-address” option in the MySQL configuration file to “0.0.0.0” to allow MySQL connection from any IP address.

To verify the settings, run:

netstat -tulnp

Initiate the phpMyAdmin container using “docker-compose up -d” and confirm successful connection to the MySQL server.

Ensure MySQL user permissions allow remote connections for phpMyAdmin access.

Connecting phpMyAdmin to an Existing MySQL Container

If an existing MySQL/MariaDB container is in place and phpMyAdmin needs linking for database management, ensure that both containers share the same Docker network.

Create a Docker network and modify the MySQL and phpMyAdmin services in the Docker Compose file to include the shared network.

Initiate the containers to seamlessly log into the MySQL instance through phpMyAdmin.

Conclusion

Integrating Docker with phpMyAdmin simplifies MySQL/MariaDB database management, streamlining operations and reducing setup complexities. Explore the deployment options further in the phpMyAdmin and MySQL documentation on Docker Hub.

Thank you for your attention! Feel free to ask any questions in the comments section below.

🤞 Don’t miss these tips!

🤞 Don’t miss these tips!

Solverwp- WordPress Theme and Plugin