Skip to content

MySQL

Curated name mysql. Adds a MySQL 8 service to the workbench in compose mode, with seeded dev credentials and a readiness healthcheck.

A relational database for local development when your stack targets MySQL (or MariaDB-compatible) - a real MySQL your app and migrations run against, with dev credentials seeded for you.

At init, or to an existing workbench:

Terminal window
monoceros init acme --with-services=mysql
monoceros add-service acme mysql

Need a second database? Add it again under a different name with --as - each instance gets its own host, data dir, and connection env:

Terminal window
monoceros add-service acme mysql --as=analytics
Terminal window
monoceros remove-service acme mysql

Or delete the service’s block from acme.yml by hand and re-run monoceros apply acme - the yml is the source of truth. (Its data volume monoceros-acme-data-mysql is removed with the workbench on monoceros remove, which backs it up first.)

acme.yml
services:
- name: mysql # host name in the container + data dir name
image: mysql:8
port: 3306 # in-container port (feeds `monoceros tunnel`)
env:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} # values live in acme.env
MYSQL_DATABASE: ${MYSQL_DATABASE}
volumes:
- data:/var/lib/mysql # the service's own Docker volume
restart: unless-stopped
healthcheck: # workspace waits for service_healthy
test:
[
CMD,
mysqladmin,
ping,
-h,
127.0.0.1,
-u,
root,
'-p${MYSQL_ROOT_PASSWORD}',
]
interval: 10s
timeout: 5s
retries: 5
connectionEnv: # → the workspace env vars below
URL: mysql://root:${MYSQL_ROOT_PASSWORD}@${host}:${port}/${MYSQL_DATABASE}
HOST: ${host}
PORT: ${port}
USER: root
PASSWORD: ${MYSQL_ROOT_PASSWORD}
DB: ${MYSQL_DATABASE}

The password is a ${VAR} reference; the real values live in acme.env (dev default monoceros for both the root password and the database), so the yml stays shareable without baking credentials in (see Workbench configuration).

Monoceros injects a connection env into the workspace container, prefixed with the service name:

VariableValue (defaults)
MYSQL_URLmysql://root:monoceros@mysql:3306/monoceros
MYSQL_HOSTmysql
MYSQL_PORT3306
MYSQL_USERroot
MYSQL_PASSWORDmonoceros
MYSQL_DBmonoceros

The connection uses the root user (the seeded MySQL image only sets the root password). The prefix is the service name, uppercased, so a second instance added with --as=analytics gets ANALYTICS_URL, … and never collides.