Skip to content

Instantly share code, notes, and snippets.

@adonley
Last active February 1, 2018 10:39
Show Gist options
  • Save adonley/3a99f848adb8d66899d01923bab34af1 to your computer and use it in GitHub Desktop.
Save adonley/3a99f848adb8d66899d01923bab34af1 to your computer and use it in GitHub Desktop.
Angular5 Live Reload Dockerfile
FROM node:8.1.2
MAINTAINER Andrew Donley <andrewjdonley@gmail.com>
RUN npm install -g @angular/cli --unsafe-perm \
&& mkdir /app
# Use this instead if you shrinkwrap.
# COPY npm-shrinkwrap.json .
COPY package-lock.json .
COPY package.json .
# Avoid reinstalling npm packages between builds by installing to different dir
RUN npm install \
&& npm cache clean -f \
&& rm -rf ~/.npm
WORKDIR /app
EXPOSE 4200
EXPOSE 49153
EXPOSE 49152
# Build with:
# docker build . -t angularApp
# Run with (4 gigs and 3 cpus for fast reload):
# docker run -it -m 4096m --cpus=3.0 -p 4200:4200 -p 49153:49153 -p 49152:49152 -v $(pwd):/app -t angularApp
# Goto: http://localhost:4200 to view running application.
ENTRYPOINT [ "sh", "-c", "cp -r /node_modules /app && /usr/local/bin/ng serve --host 0.0.0.0" ]
#!/bin/bash
DOCKER_LOCATION=$(which docker);
NODE_MODULES="./node_modules"
function main {
setUp;
run_image;
exit 0;
}
function setUp {
if [ ! -x $DOCKER_LOCATION ]; then
printf "%s\n\n" "Please install docker before using this dev method :D";
printf "\t%s\n\n" "https://www.docker.com/community-edition#/download";
exit 1;
fi
if [ -d "${NODE_MODULES}" ]; then
printf "\n\n%s\n\n" "Removing ${NODE_MODULES} directory for system compatibility";
rm -rf ${NODE_MODULES};
fi
printf "\n\n%s\n\n\n" "This will take a bit depending on internet connection speed - coffeetime";
# Build docker image
${DOCKER_LOCATION} build . -t angularApp
}
function run_image {
# 4gig, 3cpu for fast reload
${DOCKER_LOCATION} run -it -m 4096m --cpus=3.0 -p 4200:4200 -p 49153:49153 -p 49152:49152 -v $(pwd):/app -t angularApp
}
main;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment