Home / Configs / Containers / Docker Compose for MySQL and phpMyAdmin

Docker Compose for MySQL and phpMyAdmin on localhost

Run MySQL and the phpMyAdmin web page on your computer with one docker compose command.

For Docker with the Compose plugin. The image names are the official mysql and phpmyadmin images on Docker Hub.

This file starts a MySQL database and the phpMyAdmin web page together. phpMyAdmin is already set to talk to the database, so you can open it in the browser and log in. Set your passwords below and run docker compose up.

Create your config file

Type your own values. The file below updates as you type, and nothing you type leaves your browser.

Use letters and numbers

docker-compose.yml
services:
  db:
    image: mysql:8.4
    container_name: mysql-db
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: Change-root-456
      MYSQL_DATABASE: appdb
      MYSQL_USER: app
      MYSQL_PASSWORD: Change-me-123
    ports:
      - "3306:3306"
    volumes:
      - mysql-data:/var/lib/mysql

  phpmyadmin:
    image: phpmyadmin
    container_name: phpmyadmin
    restart: unless-stopped
    environment:
      PMA_HOST: db
    ports:
      - "8080:80"
    depends_on:
      - db

volumes:
  mysql-data:

How this setup works

Diagram: Browser, then phpMyAdmin, then MySQL
Browser (port you chose) → phpMyAdmin (web page) → MySQL (stores your data)

Step-by-step setup

  1. Save the file above as docker-compose.yml.
  2. Start both: docker compose up -d. The first start takes a minute while MySQL sets itself up.
  3. Open http://localhost:8080.
  4. Log in with user app and your user password, or root and the root password.
  5. To stop: docker compose down. Your data stays in the volume. Add -v to delete it too.

What the important lines mean

Common errors and how to fix them

Access denied for user
The user and password must match the values above. The passwords are only set on the first start. If you changed them later, run docker compose down -v to start with a new volume.
phpMyAdmin: #2002 Connection refused
MySQL is still starting. Wait a minute and reload. If it persists, read docker compose logs db.
port is already allocated
Another program uses that port, often an installed MySQL on 3306. Change the left number of the port line.
Your app cannot connect to the database
From your computer use 127.0.0.1 and the port above. From another container in the same file use the host db and port 3306.

Frequently asked questions

Is it safe to leave this running?
It is meant for development on your own computer. Do not publish these ports to the internet, and use strong passwords if anyone else can reach your machine.
How do I import a database in phpMyAdmin?
Open the database, choose Import and pick a .sql file. Large files may exceed the upload limit, so import them with the mysql command instead.
Where is my data stored?
In the Docker volume mysql-data. It stays until you remove the volume.

Written for: Docker Compose v2, MySQL 8.4 · Updated 2026-10-11

Free tools that help

Fix a problem with this setup

More container configs

See all 41 config generators