DevOps ~ Docker ~ Containerize Node app - rohit120582sharma/Documentation GitHub Wiki
FROM node:alpine
WORKDIR /usr/src/app
COPY ./package*.json ./
RUN npm install
COPY ./ ./
CMD ["npm", "run", "start"]
version: '3'
services:
my-mongo:
image: mongo
volumes:
- mongo-data:/data/db
expose:
- '27017'
app:
container_name: docker-node-app
restart: always
build:
context: .
dockerfile: Dockerfile
ports:
- '3000:3000'
links:
- my-mongo
depends_on:
- my-mongo
environment:
- CHOKIDAR_USEPOLLING=true
- MONGO_URL=mongodb://my-mongo/<db-name>
volumes:
mongo-data:
Run Docker Compose from the same directory:
$ docker-compose up --build
You now have a MongoDB container and Node container running on your host. Navigate to http://localhost:3000 in a web browser to see your application. You can also use docker ps
to further explore the resulting configuration.