Skip to content

Instantly share code, notes, and snippets.

@xeoncross
Last active December 28, 2021 01:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xeoncross/eefb8059945e2ea1b63f83300bd89f6f to your computer and use it in GitHub Desktop.
Save xeoncross/eefb8059945e2ea1b63f83300bd89f6f to your computer and use it in GitHub Desktop.
Quick docker setup of new database for building out project DDL / UML for RDBMS entities
MYSQL_HOST=mysqldb
MYSQL_USER=design
MYSQL_PASS=design
MYSQL_NAME=design
MYSQL_PORT=3306
version: "3.2"
services:
# backend:
# build:
# context: ./backend
# dockerfile: Dockerfile
# depends_on:
# - mysqldb
# restart: always
# ports:
# - "5000:5000"
# frontend:
# build:
# context: ./frontend
# dockerfile: Dockerfile
# ports:
# # 80 on the host, 8080 on the guest
# - "80:8080"
# restart: always
mysqldb:
build:
context: ./mysql
dockerfile: Dockerfile
ports:
- "3306:3306" # expose to host if someone wants to look at schema
environment:
- MYSQL_ROOT_HOST=${MYSQL_HOST}
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASS}
- MYSQL_DATABASE=${MYSQL_NAME}
- MYSQL_ROOT_PASSWORD=${MYSQL_PASS}
FROM mysql:5.6
COPY schema.sql /docker-entrypoint-initdb.d/
EXPOSE 3306

I often want to spin up a database design using docker so I can work on preparing a UML diagram or something to present the design to a group. This allows me to write the SQL in durable way - yet with an ephemeral db instance, while also saving the final model generated from whatever tooling (MySQL workbench) I end up using.

CREATE TABLE comments (
id INTEGER AUTO_INCREMENT,
comment TEXT,
PRIMARY KEY (id)
);
INSERT INTO comments (comment) VALUES ("This is the first comment");
INSERT INTO comments (comment) VALUES ("This another comment");
INSERT INTO comments (comment) VALUES ("This is the last comment");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment