docker.recipes

MySQL + phpMyAdmin

beginner

MySQL database server with phpMyAdmin web interface for visual database management and administration.

Overview

MySQL is the world's most widely deployed open-source relational database management system, powering millions of web applications from small WordPress sites to massive enterprise platforms. Originally developed by MySQL AB in 1995, it has become the backbone of the modern web stack, particularly in LAMP (Linux, Apache, MySQL, PHP) environments. Its reputation for speed, reliability, and ease of use has made it the go-to choice for developers who need robust data storage without the complexity of enterprise database systems. This stack combines MySQL 8.0 with phpMyAdmin, creating a complete database solution with visual management capabilities. phpMyAdmin provides a web-based interface that transforms MySQL's command-line administration into an intuitive graphical experience, allowing users to create databases, manage tables, execute queries, and handle user permissions through a browser. The two containers communicate over a dedicated Docker network, with phpMyAdmin automatically connecting to the MySQL instance without additional configuration. This combination is perfect for web developers, small to medium businesses, and anyone who needs MySQL database functionality with easy visual management. Whether you're running WordPress sites, developing PHP applications, or need a development database with administrative tools, this stack provides immediate productivity. The setup is particularly valuable for teams where not all members are comfortable with command-line database administration, as phpMyAdmin makes complex database operations accessible through its web interface.

Key Features

  • MySQL 8.0 with InnoDB storage engine providing ACID compliance and foreign key constraints
  • phpMyAdmin web interface with full MySQL administration, SQL editor, and query bookmarks
  • JSON data type support with native indexing and path-based queries in MySQL 8.0
  • Import/export functionality supporting CSV, SQL, XML, and other database formats
  • Visual database designer in phpMyAdmin for creating relationships and ER diagrams
  • MySQL Group Replication support for high availability configurations
  • Full-text search capabilities with natural language and boolean mode searching
  • User privilege management through phpMyAdmin's intuitive interface

Common Use Cases

  • 1WordPress and PHP application development with visual database management
  • 2Small to medium business applications requiring relational data storage
  • 3Web hosting environments where clients need database access without shell access
  • 4Development and testing environments for MySQL-based applications
  • 5Educational settings for teaching SQL and database administration concepts
  • 6Legacy application migration where phpMyAdmin provides familiar MySQL tooling
  • 7Multi-tenant applications where different teams need database access through web interface

Prerequisites

  • Minimum 512MB RAM available (256MB for MySQL + 128MB for phpMyAdmin)
  • Docker and Docker Compose installed on the host system
  • Ports 3306 and 8080 available on the host machine
  • Basic understanding of SQL and relational database concepts
  • Environment file (.env) with MySQL credentials configured

For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms

docker-compose.yml

docker-compose.yml
1services:
2 mysql:
3 image: mysql:8.0
4 container_name: mysql
5 restart: unless-stopped
6 environment:
7 MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
8 MYSQL_DATABASE: ${MYSQL_DATABASE}
9 MYSQL_USER: ${MYSQL_USER}
10 MYSQL_PASSWORD: ${MYSQL_PASSWORD}
11 volumes:
12 - mysql_data:/var/lib/mysql
13 ports:
14 - "3306:3306"
15 networks:
16 - mysql-network
17
18 phpmyadmin:
19 image: phpmyadmin:latest
20 container_name: phpmyadmin
21 restart: unless-stopped
22 environment:
23 PMA_HOST: mysql
24 PMA_PORT: 3306
25 ports:
26 - "8080:80"
27 depends_on:
28 - mysql
29 networks:
30 - mysql-network
31
32volumes:
33 mysql_data:
34
35networks:
36 mysql-network:
37 driver: bridge

.env Template

.env
1MYSQL_ROOT_PASSWORD=rootpassword
2MYSQL_DATABASE=myapp
3MYSQL_USER=appuser
4MYSQL_PASSWORD=changeme

Usage Notes

  1. 1Docs: https://dev.mysql.com/doc/ | phpMyAdmin: https://www.phpmyadmin.net/docs/
  2. 2Access phpMyAdmin at http://localhost:8080
  3. 3Login with root/MYSQL_ROOT_PASSWORD or MYSQL_USER/MYSQL_PASSWORD
  4. 4Backup: docker exec mysql mysqldump -u root -p --all-databases > backup.sql
  5. 5For production, set MYSQL_ROOT_HOST to restrict root access
  6. 6Data persisted in mysql_data volume - backup /var/lib/mysql regularly

Individual Services(2 services)

Copy individual services to mix and match with your existing compose files.

mysql
mysql:
  image: mysql:8.0
  container_name: mysql
  restart: unless-stopped
  environment:
    MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
    MYSQL_DATABASE: ${MYSQL_DATABASE}
    MYSQL_USER: ${MYSQL_USER}
    MYSQL_PASSWORD: ${MYSQL_PASSWORD}
  volumes:
    - mysql_data:/var/lib/mysql
  ports:
    - "3306:3306"
  networks:
    - mysql-network
phpmyadmin
phpmyadmin:
  image: phpmyadmin:latest
  container_name: phpmyadmin
  restart: unless-stopped
  environment:
    PMA_HOST: mysql
    PMA_PORT: 3306
  ports:
    - "8080:80"
  depends_on:
    - mysql
  networks:
    - mysql-network

Quick Start

terminal
1# 1. Create the compose file
2cat > docker-compose.yml << 'EOF'
3services:
4 mysql:
5 image: mysql:8.0
6 container_name: mysql
7 restart: unless-stopped
8 environment:
9 MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
10 MYSQL_DATABASE: ${MYSQL_DATABASE}
11 MYSQL_USER: ${MYSQL_USER}
12 MYSQL_PASSWORD: ${MYSQL_PASSWORD}
13 volumes:
14 - mysql_data:/var/lib/mysql
15 ports:
16 - "3306:3306"
17 networks:
18 - mysql-network
19
20 phpmyadmin:
21 image: phpmyadmin:latest
22 container_name: phpmyadmin
23 restart: unless-stopped
24 environment:
25 PMA_HOST: mysql
26 PMA_PORT: 3306
27 ports:
28 - "8080:80"
29 depends_on:
30 - mysql
31 networks:
32 - mysql-network
33
34volumes:
35 mysql_data:
36
37networks:
38 mysql-network:
39 driver: bridge
40EOF
41
42# 2. Create the .env file
43cat > .env << 'EOF'
44MYSQL_ROOT_PASSWORD=rootpassword
45MYSQL_DATABASE=myapp
46MYSQL_USER=appuser
47MYSQL_PASSWORD=changeme
48EOF
49
50# 3. Start the services
51docker compose up -d
52
53# 4. View logs
54docker compose logs -f

One-Liner

Run this command to download and set up the recipe in one step:

terminal
1curl -fsSL https://docker.recipes/api/recipes/mysql-phpmyadmin/run | bash

Troubleshooting

  • Connection refused on port 3306: Check if MySQL container started successfully and MYSQL_ROOT_PASSWORD is set in environment variables
  • phpMyAdmin shows 'mysqli_real_connect(): (HY000/2002)': Ensure both containers are on the same network and MySQL container is fully initialized before phpMyAdmin starts
  • Access denied for user 'root'@'%': Verify MYSQL_ROOT_PASSWORD matches between containers, or use MYSQL_USER/MYSQL_PASSWORD for non-root access
  • Import file size exceeded in phpMyAdmin: Increase PHP upload limits by mounting custom PHP configuration or use mysql command line for large imports
  • MySQL data lost after container restart: Confirm mysql_data volume is properly mounted and not using anonymous volumes

Community Notes

Loading...
Loading notes...

Download Recipe Kit

Get all files in a ready-to-deploy package

Includes docker-compose.yml, .env template, README, and license

Ad Space