Docker fails to install npm on remote host. Error is ENOMEM

The issue turned out to be that the EC2 instance- t2.micro- was running out of RAM. Solved it by upgrading it to a bigger type.

The nice thing about EC2 is that you can chance the instance type without having to migrate the instance.

$ docker-compose build
Building menagerie
Step 0 : FROM node:0.12.4
 ---> 96a65baf6d8a
 ---> Using cache
 ---> cf654f0bd4ac
Step 2 : ENV TARGET_DIR /opt/menagerie
 ---> Using cache
 ---> 54e21ac38ac2
Step 3 : RUN mkdir $TARGET_DIR
 ---> Using cache
 ---> 6e1948fe3e27
Step 4 : WORKDIR $TARGET_DIR
 ---> Using cache
 ---> fc6a7c8e4c9c
Step 5 : ENV DEBIAN_FRONTEND noninteractive
 ---> Using cache
 ---> e7bd782df11e
Step 6 : RUN npm i -g pm2@0.15.7
 ---> Using cache
 ---> 846fa09159ec
Step 7 : COPY package.json /tmp/package.json
 ---> Using cache
 ---> b228222559db
Step 8 : RUN cd /tmp && npm install --quiet
 ---> Running in 4f8fafd6b045
npm WARN deprecated grunt-lib-contrib@0.7.1: DEPRECATED. See readme: https://github.com/gruntjs/grunt-lib-contrib
npm WARN optional dep failed, continuing fsevents@1.0.5
npm ERR! Linux 3.13.0-53-generic
npm ERR! argv "node" "/usr/local/bin/npm" "install" "--quiet"
npm ERR! node v0.12.4
npm ERR! npm  v2.11.1
npm ERR! code ENOMEM
npm ERR! errno ENOMEM
npm ERR! syscall spawn

npm ERR! spawn ENOMEM
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

In the dashboard, from the instance list. You have to right click on the instance and select Instance State then stop it.

Then you have to select Instance Settings and select Change Instance Type. That's it. Note that you will loose all tmp files. It will took me less than 5 minutes all together.

Note, you might want to create an EBS snapshot before trying this. Check out this about resizing EBS