From e654ba63abe7e175d1a43168d2a1e2791d037cc1 Mon Sep 17 00:00:00 2001 From: Alex MacArthur Date: Tue, 3 Sep 2019 15:14:00 -0500 Subject: [PATCH] Add base README and configs for mysql & mongo. --- .gitignore | 1 + README.md | 13 +++++++++++++ mongo/README.md | 18 ++++++++++++++++++ mongo/docker-compose.yml | 12 ++++++++++++ mysql/README.md | 17 +++++++++++++++++ mysql/docker-compose.yml | 13 +++++++++++++ 6 files changed, 74 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 mongo/README.md create mode 100644 mongo/docker-compose.yml create mode 100644 mysql/README.md create mode 100644 mysql/docker-compose.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1269488 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +data diff --git a/README.md b/README.md new file mode 100644 index 0000000..e2bd8b0 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# Local Docker DB + +## What? +A collection of Docker Compose files I've used to quickly spin local databases of various sorts. + +## Why? +Because I've oft needed them, particularly when I just don't wanna deal with the hassle of spinning up a DB on my own system. + +## How? +Clone the repo or copy a `docker-compose.yml` file to your system, `cd` into that directory, and turn it on with `docker-compose up`. For a full reference on how to use Docker Compose, [go here](https://docs.docker.com/compose/reference/). + +## Local Persistence +In each setup, your data is configured to be stored locally in a `./data` directory. If that directory doesn't exist, it'll be created automatically. diff --git a/mongo/README.md b/mongo/README.md new file mode 100644 index 0000000..a95dea5 --- /dev/null +++ b/mongo/README.md @@ -0,0 +1,18 @@ +# Enter the Container w/ Bash + +`docker-compose exec --user root db /bin/bash` + +# Enter the Mongo Shell + +`docker-compose exec --user root db mongo` + +# Create a DB w/ User + +While in the shell, run the following: + +``` +use admin; +db.auth("user", "password"); +use myDatabase; +db.createUser({user: "user", pwd: "password", roles:[{role: "readWrite" , db:"myDatabase"}]}); +``` diff --git a/mongo/docker-compose.yml b/mongo/docker-compose.yml new file mode 100644 index 0000000..35a0f12 --- /dev/null +++ b/mongo/docker-compose.yml @@ -0,0 +1,12 @@ +version: '3' + +services: + db: + image: mongo:latest + volumes: + - ./data:/data/db + ports: + - 27017:27017 + environment: + MONGO_INITDB_ROOT_USERNAME: user + MONGO_INITDB_ROOT_PASSWORD: password diff --git a/mysql/README.md b/mysql/README.md new file mode 100644 index 0000000..712566e --- /dev/null +++ b/mysql/README.md @@ -0,0 +1,17 @@ +# Enter the Container w/ Bash + +`docker-compose exec --user root db /bin/bash` + +# Enter the MySQL Shell + +`docker-compose exec --user root db mysql -u root -p` + +When prompted, enter `root` as the password. + +# Create a DB + +While inside the shell, run the following: + +``` +CREATE DATABASE mydatabase; +``` diff --git a/mysql/docker-compose.yml b/mysql/docker-compose.yml new file mode 100644 index 0000000..9cdc7b9 --- /dev/null +++ b/mysql/docker-compose.yml @@ -0,0 +1,13 @@ +version: '3' + +services: + db: + container_name: docker-local-mysql + image: mysql:5.7.21 + volumes: + - "./data:/var/lib/mysql" + restart: always + ports: + - 3306:3306 + environment: + MYSQL_ROOT_PASSWORD: root