Coder Social home page Coder Social logo

qima / node-nvm Goto Github PK

View Code? Open in Web Editor NEW

This project forked from iliyan-trifonov/node-nvm

0.0 2.0 0.0 15 KB

A docker image/container to run NodeJS apps. The node version is specified and ran with nvm.

Home Page: https://registry.hub.docker.com/u/iliyan/docker-node-nvm/

License: MIT License

Shell 100.00%

node-nvm's Introduction

node-nvm

A docker image/container to run NodeJS apps. The node version is specified and ran with nvm.

Check the automatic build in the Docker's official registry here.

Node.js versions supported: 0.12.2, 0.12.3, 0.12.4, 0.12.5, 0.12.6, 0.12.7, 4.0.0, 4.1.0, 4.1.1, 4.1.2, 4.2.0, 4.2.1, 4.2.2, 4.2.3, 5.0.0, 5.1.0, 5.1.1, 6.3.1, 6.5.0, 6.6.0, 6.9.1. 7.6.0

I am using this image to run my own node apps. I am going to update it when a new node version is out and also when I need more or different tools installed.

The ready made image can be used that way:

docker run ... iliyan/docker-node-nvm:NODE_VERSION

First check if the NODE_VERSION tag exists in the repo. The tag will always be the same as the NodeJS version installed by the code tagged. Sometimes I need to add new features which can be seen only on latest commits on the master branch and they will be available in the next tag. That means if you see a feature that is missing in the tag you use it definitely is in the latest commits. The easiest way to use the latest is to just run the container without specifying a tag:

docker pull iliyan/docker-node-nvm
docker run ... iliyan/docker-node-nvm

Currently it uses pm2 to run the app.

You can run the container once to do some job or continuously for a whole application.

The container needs a volume on /myapp and by default the command is looking for the main app file at /myapp/src/app.js:

docker run ... -v /home/yourusername/yournodeapp:/myapp

If your app has a different structure you can specify the main js file like this(full path can be used too):

#server.js is in yournodeapp/
docker run ... -e 'APP_MAIN=server.js'
#or with a full path which is the same as the previous command:
docker run ... -e 'APP_MAIN=/myapp/server.js'

You will probably need to set a time zone in which the node server will run. This can be done with the TIME_ZONE env variable:

docker run ... -e 'TIME_ZONE=Europe/Berlin'

You can also assign an UID to execute the node application with a specific user that exists on the host machine:

docker run ... -u 1000

The volume yournodeapp/ dir will be automatically owned by the internal node user (respectfully the external -u user) on container's start.

Cpu and memory limit can be specified while executing docker run:

docker run ... -m 512m -c 512

A typical docker run command should look like this:

docker run -d --name mynodeapp -v /yourusername/yournodeapp:/myapp/ -e 'APP_MAIN=server.js' -e 'TIME_ZONE=Europe/Berlin' -p HOSTIP:HOSTPORT:APPPORT -u 1000 iliyan/docker-node-nvm:NODE_VERSION

If you check in the Dockerfile you will see that a new user node is created and used to install all the required files and run the application. The same user is also given some limited sudo permissions to run additional commands.

There is an example build shell script here. It can be used as a template to build your own image from the Dockerfile. Don't forget to set the proper tag there.

node-nvm's People

Contributors

iliyan-trifonov avatar

Watchers

马骐 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.