Skip to content

Instantly share code, notes, and snippets.

@juanpablocs
Last active October 15, 2018 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanpablocs/09bb6f66011128a7619ed921b406d284 to your computer and use it in GitHub Desktop.
Save juanpablocs/09bb6f66011128a7619ed921b406d284 to your computer and use it in GitHub Desktop.
Docker nodejs image and container with docker-compose.yml

package.json

{
  "name": "orbis",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "start": "node ./index.js"
  },
  "dependencies": {
    "express": "^4.16.4"
  }
}

index.js

const express = require('express');
const app = express();

app.get('/', (req, res)=>{
    res.send('Hello mundo');
});

app.listen('3000', ()=>{
    console.log('open port');
});

Dockerfile

FROM node:8.9-alpine
WORKDIR /app
COPY ["package.json", "./"]
RUN npm install

Build Image

docker build . -t node-express

docker-compose.yml

version: '3'

services:
  orbis:
    container_name: orbis_express
    image: node-express
    environment:
      NODE_ENV: production
    volumes:
      - "$PWD/:/app"
      - /app/node_modules
    working_dir: /app
    ports:
      - 3000:3000
    command: ["npm", "start"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment