01The Database Decision That Shapes Your Stack
Choosing a database is one of the most consequential decisions in any project, and it's often made too quickly. I've run all three major open source relational databases in Docker — PostgreSQL, MySQL, and MariaDB — across dozens of projects over the past eight years. Each has clear strengths, and the "best" choice depends entirely on your use case.
This guide skips the theoretical benchmarks (which rarely reflect real-world performance) and focuses on the practical differences that matter when you're running databases in Docker containers.
02PostgreSQL: The Versatile Workhorse
PostgreSQL is my default choice for new projects, and it's what most modern applications expect. Here's why:
Standards compliance: PostgreSQL follows the SQL standard more closely than MySQL/MariaDB. This means fewer surprises when writing complex queries, and easier migration between databases if needed.
Advanced features: JSON/JSONB support, full-text search, window functions, CTEs, materialized views, and array types are all built-in and well-optimized. You can often skip adding Redis or Elasticsearch by leveraging PostgreSQL's native capabilities.
Data integrity: PostgreSQL is strict about data types and constraints by default. MySQL's historical permissiveness (silently truncating strings, accepting invalid dates) has caused more production bugs than I can count.
Docker experience: The official postgres image is excellent. It supports initialization scripts, easy configuration via environment variables, and works well with connection poolers like PgBouncer.
When to choose PostgreSQL: New applications, complex query requirements, data integrity is critical, you need JSONB or full-text search, or the application specifically requires it (Nextcloud, Gitea, many modern apps).
[docker-compose.yml]
1services: 2 db: 3 image: postgres:16-alpine4 restart: unless-stopped5 volumes: 6 - pgdata:/var/lib/postgresql/data7 environment: 8 POSTGRES_DB: myapp9 POSTGRES_USER: myapp10 POSTGRES_PASSWORD: ${DB_PASSWORD}11 healthcheck: 12 test: ["CMD-SHELL", "pg_isready -U myapp"]13 interval: 10s14 timeout: 5s15 retries: 51617volumes: 18 pgdata: 03MySQL: The Legacy Standard
MySQL is the world's most widely deployed open source database. Its biggest advantage is compatibility — if an application supports "a database," it almost certainly supports MySQL.
Performance for simple queries: For straightforward CRUD operations (insert, select, update, delete) with proper indexing, MySQL is fast and efficient. It's well-optimized for web application workloads.
Replication: MySQL's replication is mature and well-documented. Setting up read replicas is straightforward, and tools like ProxySQL make connection routing easy.
Ecosystem: phpMyAdmin, MySQL Workbench, Percona tools, and decades of Stack Overflow answers. Whatever problem you encounter, someone has solved it before.
The Oracle factor: Since Oracle acquired MySQL, the community has been increasingly cautious. Oracle's track record with open source projects is mixed, and features that were free have moved to enterprise-only editions.
When to choose MySQL: Legacy applications, WordPress (which is heavily MySQL-optimized), applications that specifically require MySQL, or when your team has deep MySQL expertise.
04MariaDB: The Community Fork
MariaDB was forked from MySQL in 2009 by MySQL's original creator after the Oracle acquisition. It's designed to be a drop-in replacement for MySQL while adding features and maintaining community governance.
MySQL compatibility: MariaDB reads MySQL data files and understands the MySQL protocol. Most MySQL applications work with MariaDB without changes. The migration path is usually painless.
Additional engines: MariaDB includes storage engines like Aria (crash-safe replacement for MyISAM) and ColumnStore (for analytics workloads) that MySQL doesn't have.
Community governance: MariaDB Foundation ensures the project stays open source. No enterprise-only features, no CLA requirements for contributions.
Performance: For most workloads, MariaDB and MySQL perform similarly. MariaDB has some query optimizer improvements that help with complex queries.
When to choose MariaDB: You want MySQL compatibility without Oracle, WordPress or other MySQL apps where you want a community-governed alternative, or your Linux distribution ships MariaDB by default.
05Practical Docker Comparison
From an operational perspective in Docker, here are the differences that matter daily:
Image sizes (Alpine variants): PostgreSQL 16-alpine is about 80MB, MySQL 8.4 doesn't have an official Alpine variant (about 200MB), MariaDB 11-alpine is about 100MB.
Startup time: PostgreSQL is fastest, typically ready in 2-3 seconds. MariaDB is similar. MySQL is slower, often 5-10 seconds for first initialization.
Backup commands: PostgreSQL uses pg_dump/pg_dumpall, MySQL and MariaDB both use mysqldump. All work well from Docker exec.
Resource usage: PostgreSQL is more memory-efficient for complex queries. MySQL/MariaDB are slightly lighter for simple workloads.
My recommendation: Use PostgreSQL for new projects. Use MariaDB if you need MySQL compatibility. Use MySQL only if the application explicitly requires it.
Browse our database recipes for Docker Compose configurations of all three databases with various companion tools like admin panels, backup solutions, and replication setups.