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.
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MYSQL_HOST=mysqldb | |
MYSQL_USER=design | |
MYSQL_PASS=design | |
MYSQL_NAME=design | |
MYSQL_PORT=3306 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM mysql:5.6 | |
COPY schema.sql /docker-entrypoint-initdb.d/ | |
EXPOSE 3306 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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