MySQL and phpMyAdmin using Docker Compose
As a web developer, having a reliable and isolated environment for your database is crucial. Instead of installing MySQL and phpMyAdmin directly on your system, Docker allows you to set up both tools in containers — quickly, cleanly, and consistently across different projects.
In this guide, we’ll walk through running MySQL with phpMyAdmin using Docker Compose. This setup is perfect for local development and works seamlessly across Windows, macOS, and Linux.
✅ Prerequisites
Before we begin, make sure you have the following installed:
- Docker
- Docker Compose
🛠 Step-by-Step Guide
📁 Step 1: Create a Project Directory
Open your terminal and create a new directory for your Docker setup:
mkdir mysql-docker-setup
cd mysql-docker-setup
📝 Step 2: Create a docker-compose.yml
File
Inside the project directory, create a file named docker-compose.yml
and paste the following content:
services:
#db
db:
image: 'mysql/mysql-server:8.0'
container_name: mysql
restart: unless-stopped
ports:
- '3306:3306'
volumes:
- mysqldata:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_ROOT_HOST: '%'
MYSQL_DATABASE: mydb
MYSQL_USER: user
MYSQL_PASSWORD: root
MYSQL_ALLOW_EMPTY_PASSWORD: 1
networks:
- mysql-network
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 10s
timeout: 5s
retries: 3
#phpmyadmin
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
restart: unless-stopped
ports:
- '8080:80'
environment:
PMA_HOST: db
PMA_PORT: 3306
PMA_USER: user
PMA_PASSWORD: root
depends_on:
- db
networks:
- mysql-network
networks:
mysql-network:
driver: bridge
volumes:
mysqldata:
driver: local
This configuration does the following:
- Sets up a MySQL 8 container with user
user
and passwordroot
- Persist data using a Docker volume
- Connects phpMyAdmin to MySQL for easy GUI access via your browser
- Exposes MySQL on port
3306
and phpMyAdmin on port8080
🚀 Step 3: Start the Containers
In the terminal, run:
docker compose up -d
Docker will download the necessary images and start both containers in the background.
✅ Step 4: Access phpMyAdmin
Once the containers are running, open your browser and go to:
http://localhost:8080
Log in using:
-
Username:
user
-
Password:
root
You should now see the phpMyAdmin interface connected to your MySQL database!
🧼 Step 5: Stop and Remove Containers (Optional)
When you’re done, you can stop and remove everything with:
docker compose down
🧩 Conclusion
Github Link: https://github.com/rafi021/mysql-phpmyadmin-docker-compose
Youtube: https://youtu.be/lkR__D9NEYc
Using Docker for local database development is a game-changer. It keeps your environment clean, reproduces setups, and saves time across projects. With just one YAML file and a couple of commands, you’re ready to build and test apps using MySQL with a GUI frontend like phpMyAdmin.
Let me know in the comments if you’d like to see a similar guide for PostgreSQL, MongoDB, or other services!
Top comments (0)