-
Notifications
You must be signed in to change notification settings - Fork 0
Docker Compose Example
Xyranaut edited this page Jun 1, 2026
·
1 revision
If you like Docker, docker compose is a tidy way to run a MySQL for your open.mp
server — one file describes the database, and it comes back the same every time.
This runs the MySQL part in Docker. Your open.mp server can run on the host (or also in a container — but the host is simplest while learning).
services:
mysql:
image: mysql:8.4
container_name: omp-mysql
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ompdb
MYSQL_USER: omp_app
MYSQL_PASSWORD: ${OMP_DB_PASS}
ports:
- "3306:3306"
volumes:
- mysql-data:/var/lib/mysql # data survives restarts
- ./init:/docker-entrypoint-initdb.d # *.sql here run on first start
command: --require-secure-transport=ON # server-side: insist on TLS
volumes:
mysql-data:MYSQL_ROOT_PASSWORD=a-strong-root-password
OMP_DB_PASS=a-strong-app-passwordCompose auto-reads .env. Don't commit it.
Put SQL files in ./init/ — MySQL runs them once, when the data volume is first
created. For example ./init/01-grants.sql:
-- the compose env already made omp_app; tighten it to least privilege + TLS
ALTER USER 'omp_app'@'%' REQUIRE SSL;
-- (your CREATE TABLE statements can also go here, or let the gamemode create them)docker compose up -d # start in the background
docker compose logs -f mysql# watch startup
docker compose down # stop (data kept in the volume)
docker compose down -v # stop AND delete data (careful!)From a server on the host:
new MySQLConfig:cfg = mysql_config_create();
mysql_config_set(cfg, SSL_MODE, SSL_MODE_REQUIRED);
g_DB = mysql_connect("127.0.0.1", "omp_app", "${OMP_DB_PASS}", "ompdb", cfg);(Set OMP_DB_PASS in the server's environment too — same value as .env.)
docker compose exec mysql \
mysqldump -uroot -p"$MYSQL_ROOT_PASSWORD" --single-transaction ompdb \
| gzip > ompdb-$(date +%F).sql.gzMore in Backups & maintenance.
-
--require-secure-transport=ONmakes the server refuse non-TLS connections — belt-and-suspenders with omp-MySQL's own fail-closed TLS. - The named volume (
mysql-data) is what persists your data. Deleting it (down -v) wipes everything. - Pin a version (
mysql:8.4) rather thanlatestso upgrades are deliberate.
Next: Installing MySQL · Getting started
Understand
Use
- Installing MySQL
- Docker Compose
- Getting started
- Configuration
- SQL crash course
- Designing your tables
- Storing game data
- Dates & times
- First queries
- Async patterns
- Reading results
- Prepared statements
- Passwords & hashing
- Transactions
- Models (active-record)
- Tutorial: login system
- mysql-admin demo
Deeper
Reference