Friday 9 June 2017

Setting up node.js + mongodb environment in Docker Compose

I'm trying to set up Node.js and MongoDB in a docker compose. I tried following this tutorial. These are the appropriate files

Dockerfile

FROM mhart/alpine-node:base-6

RUN mkdir /app
WORKDIR /app
ADD . .

EXPOSE 8000
CMD ["node", "app.js"]

My node.js app runs locally on port 8000

docker-compose.yml

version: "3"
services:
  web:
    build: .
    volumes:
      - ./:/app
    ports:
      - "8000:8000"
    links:
      - mongo
  mongo:
    image: mongo
    ports:
      - "27017:27017"

I try creating a mapping between the container's port 8000 and the host's 8000. However, when I try connecting to localhost:8000 in Google Chrome, I get localhost did not send any data

Another question I had that the article failed to address was how I can name my database.

app.js

...
mongoose.connect('mongodb://mongo:27017');

What exactly is this URI doing? How can I tell it to use the database my_db ?



via Carpetfizz

No comments:

Post a Comment