Running Angular2-CLI from a Docker Container

MD
R
Markdown

This recipe assumes that you have an Angular2 CLI enabled app already setup and that you are creating the docker container (ie. running the commands) form inside the folder of your Angular App. Version used: Angular CLI version (1.1.3)

This recipe includes the Dockerfile and the instructions to start the NG CLI from the container and use your local browser

1. Create the Docker File

FROM node:7.9
RUN mkdir -p /var/app
WORKDIR /var/app
RUN apt-get update
RUN apt-get install -y vim
COPY ./package.json /var/app
RUN npm install -g @angular/cli
RUN npm install
COPY ./ /var/app
ENV NODE_ENV=development NODE_PATH=./lib:.
EXPOSE 5858
EXPOSE 4200
VOLUME /var/app/node_modules

2. Build the container

docker build -t ctw-recipes .

3. Create an instance of the container

docker stop recipes; docker rm recipes; docker run -it -p 5858:5858 -p 4200:4200 -v \"$PWD:/var/app\" -v recipes-node-modules:/var/app/node_modules --name recipes ctw-recipes bash; exit 0

4. Start Angular CLI (inside the container terminal of course...)

ng serve --host 0.0.0.0

5. To clear the container image and all instances

docker stop recipes; docker rm recipes; docker rmi ctw-recipes; exit 0

Created on 6/24/2017