Docker Images: basic Node setup

Use this as a template for node apps:

#-------------------------------------------------------------------------------
# Base

FROM ruby:14.13.1-alpine

SHELL ["/bin/ash", "-c"]

#-------------------------------------------------------------------------------
# Packages

RUN set -exo pipefail              && \
                                      \
    echo 'Install system packages' && \
    apk add --update --no-cache \
      build-base                \
      shadow

#-------------------------------------------------------------------------------
# Workspace

RUN set -exo pipefail       && \
                               \
    echo 'Create workspace' && \
    mkdir -p /work

WORKDIR /work

#-------------------------------------------------------------------------------
# User

ARG HOST_USER_UID=1000
ARG HOST_USER_GID=1000

RUN set -exo pipefail                                && \
                                                        \
    echo 'Create the git user and group from host'   && \
    deluser --remove-home node                       && \
    groupadd -g $HOST_USER_GID notroot               && \
    useradd -lm -u $HOST_USER_UID -g notroot notroot && \
                                                        \
    echo 'Set direcotry permissions'                 && \
    chown notroot:notroot /work

#-------------------------------------------------------------------------------
# Command

CMD ["sh"]

Build it like this:

docker build \
  --build-arg=HOST_USER_UID=`id -u` \
  --build-arg=HOST_USER_GID=`id -g` \
  -t node-project \
  "$PWD"

Or in docker-compose using:

---

services:
  app:
    build:
      args:
        HOST_USER_UID: ${HOST_USER_UID}
        HOST_USER_GID: ${HOST_USER_GID}
      context: .
      dockerfile: ./Dockerfile