Public | Automated Build

Last pushed: a month ago
Short Description
JS development using Docker
Full Description

JavaScript development using Docker

Everything below should be useful for everyone, who developing using node.

Docker can be incredibly powerfull for isolating your dev environment!

How it works?

  1. Install Docker.
  2. Run install script and do not forget to source updated configuration (you will be notified with more detail instructions during the process).
  3. Do this:
    cd ~/my-cool-project // Move to your project directory
    jsd 8000             // This is a shortcuf for docker run --volumes-from nvm-cache -p 8000:8000 -i -t -v $(pwd):/src i1skn/jsdev
                      // Run Linux environment with latest Node installed, also open 8000 port.
                      // When container starting - it will mount current directory to /src
    npm install          // Install deps
    npm start            // Run the server
    

Why you want to develop NodeJS with Docker?

  • Finally Docker released versions for Mac and Windows, which implements "native" approach.
  • Host machine is not polluted with npm nvm global node modules stuff.
  • You can copy your node environment and easily restore it somewhere else (Read: you can share it with your team).
  • You can run your code on production like environment.
  • Things like node-gyp is not a problem anymore!

Why just not use official node Docker image?

Official image has only one installed node version per image. So basically to run another node version, you will need another image.
This image give you possibility to use multiple node versions within the same image.

Under the hood

Basically we take debian image and install python, gcc and other useful stuff.
Next we install nvm to be able use multiple node versions.
So now when you run a container from this image you will need to install needed node version. If we will do this way, time to run a container will be around 1 minute (depend from internet connection and CPU) which is not really convenient.
But we can improve this approach with caching!

NVM Cache

Because we want to be able to run containers with different node versions, there are no node in the image as we mentioned before. This mean, that every time we run a container - nvm is about to install node. To prevent this we can create Data Volume Container to store nvm cache.

docker create -v /root/.nvm -v /root/.node-gyp --name nvm-cache i1skn/jsdev

So now you do not need to download node every time you run a container.

Run dev environment

docker run --volumes-from nvm-cache -p 8080:8080 -i -t -e VER=6.2.2 -v $(pwd):/src i1skn/jsdev

After container created you will be automatically moved to /src if it exist.

  • VER (optional) is node version, default to latest version.

This looks a bit long, but we have SHORCUT for it.

<a name="install"></a>Install

To install, you can use the install script using cURL:

curl -o- https://raw.githubusercontent.com/i1skn/docker-jsdev/master/install.sh | bash

Script will create NVM Cache container and also add jsd tool, which will make usage even simplier!

So, instead of:

docker run --volumes-from nvm-cache -p 8080:8080 -p 8000:8000 -p 3000:3000-i -t -e VER=6.2.2 -v $(pwd):/src i1skn/jsdev

you can type

jsd -v 4.2.2 3000 8000 8080

License

MIT

Docker Pull Command
Owner
i1skn
Source Repository

Comments (0)