MySQL
Curated name mysql. Adds a MySQL 8 service to the workbench in compose mode,
with seeded dev credentials and a readiness healthcheck.
What it’s for
Section titled “What it’s for”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.
Add it
Section titled “Add it”At init, or to an existing workbench:
monoceros init acme --with-services=mysqlmonoceros add-service acme mysqlNeed a second database? Add it again under a different name with --as - each
instance gets its own host, data dir, and connection env:
monoceros add-service acme mysql --as=analyticsRemove it
Section titled “Remove it”monoceros remove-service acme mysqlOr 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.)
The yml entry
Section titled “The yml entry”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).
What your code sees
Section titled “What your code sees”Monoceros injects a connection env into the workspace container, prefixed with the service name:
| Variable | Value (defaults) |
|---|---|
MYSQL_URL | mysql://root:monoceros@mysql:3306/monoceros |
MYSQL_HOST | mysql |
MYSQL_PORT | 3306 |
MYSQL_USER | root |
MYSQL_PASSWORD | monoceros |
MYSQL_DB | monoceros |
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.