Skip to content

Instantly share code, notes, and snippets.

@jimmylin212
Created May 21, 2018 07:53
Show Gist options
  • Save jimmylin212/b53d72885b0f55c869901bdb85a8a56f to your computer and use it in GitHub Desktop.
Save jimmylin212/b53d72885b0f55c869901bdb85a8a56f to your computer and use it in GitHub Desktop.
Build the node environment by this docker file.
FROM ubuntu:latest
## Initailize
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
## Global setting
ENV NODE_VERSION 8.11.2
ENV NVM_VERSION 0.33.1
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
## Install prerequests
RUN apt-get update
RUN apt-get install -y curl openssh-server git sudo openjdk-8-jre
## For the sshd setting, if you don't want to login by ssh, it's okay to delete the follow part
RUN mkdir /var/run/sshd
RUN useradd -ms /bin/bash node
RUN sudo adduser node sudo
RUN echo 'node:node' | chpasswd
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
## Install nvm
USER node
RUN mkdir /home/node/.nvm
ENV NVM_DIR /home/node/.nvm
RUN curl https://raw.githubusercontent.com/creationix/nvm/v$NVM_VERSION/install.sh | bash \
&& . $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default
## Set the node path to correct one
ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/v$NODE_VERSION/bin:$PATH
USER root
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment