Skip to content

Instantly share code, notes, and snippets.

@RyanCCollins
Last active November 22, 2016 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save RyanCCollins/d2e9401a63afdc43343b to your computer and use it in GitHub Desktop.
Save RyanCCollins/d2e9401a63afdc43343b to your computer and use it in GitHub Desktop.
Install the latest working version of NodeJS in Docker with correct permissions.

Dockerfile

#
# Node.js Dockerfile
#
# https://github.com/dockerfile/nodejs
#

FROM node:4-onbuild

# Install Node.js
RUN apt-get update \
  && npm update -g npm

# install sudo and map the docker user
RUN apt-get -y install sudo

RUN useradd -m docker && echo "docker:docker" | chpasswd && adduser docker sudo

# Define working directory.
WORKDIR /data

EXPOSE 9000
EXPOSE 3000

# Define default command.

USER docker
CMD ["bash"]

Install latest NodeJS Image

docker run -t -i -v pwd/:data node:latest /bin/bash

Then, to fix the broken install of Node:

curl -L https://www.npmjs.org/install.sh | sh && npm cache clean

If you get any EACCESS errors try this:

sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}

and this:

Remove everything but npm from global node_modules folder (/usr/lib/node_modules)

npm -g ls | grep -v 'npm@' | awk '/@/ {print $2}' | awk -F@ '{print $1}' | xargs npm -g rm
mkdir "$HOME/npm"
npm config set prefix "$HOME/npm"
printf "NODE_PATH=$NODE_PATH:$HOME/npm/lib/node_modules\nPATH=$PATH:$HOME/npm:$HOME/npm/bin\n" >> ~/.bashrc && source ~/.bashrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment