Skip to content

Instantly share code, notes, and snippets.

@jfeliweb
Created April 21, 2019 03:23
Show Gist options
  • Save jfeliweb/aaf50619fdff1a9c5f5e1799275dad91 to your computer and use it in GitHub Desktop.
Save jfeliweb/aaf50619fdff1a9c5f5e1799275dad91 to your computer and use it in GitHub Desktop.
Node JS and MongoDB in Docker

Node JS, MongoDB, and Express JS App

To get going:

docker-compose build

after the build than docker up

docker-compose up

To get started installing:

npm install mongoose --save

after mongoose is done installing docker up

docker-compose up

Helpful CMD

*Get into mongo on MacOS

  • Get container id
docker container ls
  • access mongo cli You can run the interactive mongo shell by running the following command:
docker run -it -p 28000:27017 --name mongoContainer mongo:latest mongo

Otherwise, if your container is already running, you can use the exec command:

docker exec -it mongoContainer mongo
  • Get into mongo on windows
  • Get container id
docker container ls
  • access mongo cli
winpty docker exec -it <container-id> //bin//sh
FROM node:latest
RUN mkdir /app
WORKDIR /app
COPY package.json package.json
RUN npm install
COPY . .
EXPOSE 3000
RUN npm install -g nodemon
CMD [ "nodemon", "app.js"]
version: "3"
services:
app:
container_name: mlp-app
restart: always
build: ./
ports:
- "3000:3000"
volumes:
- .:/app
links:
- mongo
mongo:
container_name: mongo
image: mongo
volumes:
- ./data/db
ports:
- "27017:27017"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment