Skip to content

Docker Compose Example

Xyranaut edited this page Jun 1, 2026 · 1 revision

Docker Compose example (MySQL for your server)

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).

docker-compose.yml

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:

.env (keep secrets out of the compose file)

MYSQL_ROOT_PASSWORD=a-strong-root-password
OMP_DB_PASS=a-strong-app-password

Compose auto-reads .env. Don't commit it.

Optional: create tables / a least-privilege user on first run

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)

Run it

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!)

Point omp-MySQL at it

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.)

Backups with Compose

docker compose exec mysql \
  mysqldump -uroot -p"$MYSQL_ROOT_PASSWORD" --single-transaction ompdb \
  | gzip > ompdb-$(date +%F).sql.gz

More in Backups & maintenance.

Notes

  • --require-secure-transport=ON makes 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 than latest so upgrades are deliberate.

Next: Installing MySQL · Getting started

Clone this wiki locally