nahkar
1/7/2018 - 8:51 PM

Docker start

Docker start

var express = require('express')
var app = express()

app.get('/', function (req, res) {
  res.send('Hello World!')
})

app.listen(8081, function () {
  console.log('app listening on port 8081!')
})

FROM node:7
WORKDIR /app
COPY package.json /app
RUN npm install
COPY . /app
CMD node index.js
EXPOSE 8082

create image
docker build -t hello-world .      
open image
docker run -p 8082:8081 hello-world


docker ps - show containers
docker stop your-container-id - stop container
docker rm your-container-id - remove container
docker rmi hello-world - remove image


docker-compose.yml

version: '3'
services: 
  web: 
    image: docker-node-express-mongoapp
    build: ./web-site
    command: node index.js
    ports:
      - "3000:3000"
    volumes:
      - ./web-site:/usr/src/app
      - /usr/src/app/node_modules
    depends_on:
      - "mongo"
      mongo:
        image: "mongo"
      ports:
         - "27017:27017"
      adminmongo
        image: "mrvautin/adminmongo"
        ports:
          - "1234:1234"
          
Build & Run
Build the container:
docker-compose build
Run the container
docker-compose up
If you don't know the ip for your newly created node+express app use the ip used by the docker machine
docker-machine ip
Open the app in your browser
http://THE-IP:3000/testFind
If you want to browse the database open the mongo admin and add "mongodb://mongo/test" as the database connection and choose whatever name you like
http://THE-IP:1234/