From 4458afbfafc31d41cbc6e13234c736b61c2c5fcb Mon Sep 17 00:00:00 2001 From: James Sheppard Date: Thu, 29 Dec 2022 21:49:55 +0000 Subject: [PATCH] Create a Mongo instance as a Docker container and update README --- .gitignore | 3 +++ README.md | 9 ++++++++- docker-compose.yaml | 13 +++++++++++++ server/.env.sample | 1 + 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 docker-compose.yaml create mode 100644 server/.env.sample diff --git a/.gitignore b/.gitignore index 0d5db5f..b310ab8 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,6 @@ .DS_Store + +# docker volumes +/dockervolume \ No newline at end of file diff --git a/README.md b/README.md index e54e891..ac1b5d5 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,9 @@ A companion app for playing [charades](https://en.wikipedia.org/wiki/Charades) To run this server, you have to connect to a MongoDB database. Your server will do this automatically once you've set the MONGO_URI environment variable. -You have at least three options for getting a MONGO_URI for development: +You have at least four options for getting a MONGO_URI for development: +- (Super Easy) Run MongoDB in a Docker container using Docker Compose with the command `docker compose up` - (Easiest) Slack Andy and ask for your own database on his Mongo Atlas account, he'll send you a URI - (Easy) Sign up for Mongo Atlas yourself and create a databse for yourself, find the URI by going through the 'connect' flow - (Probably Easy) Run MongoDB on your machine locally, figure out your own URI @@ -20,6 +21,12 @@ Set your `MONGO_URI` evironment variable in a `.env` file inside `server/`. If y MONGO_URI="mongodb+srv://:@cluster0-cusns.mongodb.net/?retryWrites=true&w=majority" ``` +If you're using Docker Compose, set you `MONGO_URI` to: + +``` +MONGO_URI="mongodb://admin:password@localhost:27017?retryWrites=true&w=majority" +``` + I put an example `.env` file in `.env.sample` feel free to `mv .env.sample .env` to get started. ## To Test diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..7bb1bed --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,13 @@ +version: '3' +services: + mongo: + image: mongo:5.0 + restart: always + ports: + - 27017:27017 + environment: + - MONGO_INITDB_ROOT_USERNAME=admin + - MONGO_INITDB_ROOT_PASSWORD=password + container_name: mongo + volumes: + - './dockervolume/mongodb:/data/db' \ No newline at end of file diff --git a/server/.env.sample b/server/.env.sample new file mode 100644 index 0000000..d40926f --- /dev/null +++ b/server/.env.sample @@ -0,0 +1 @@ +MONGO_URI="mongodb://admin:password@localhost:27017?retryWrites=true&w=majority" \ No newline at end of file