As a developer I try to install as few packages as possible and try to do as much as possible in Docker containers. Otherwise I have a to install a lot of dependencies, that need to be updated. Think of the dependencies for developing a website, like Ruby for building my Jekyll sites, .NET for the API-backend or Node for the SPA-frontends I build.

Today I wanted to build a simple Angular website to test something. To just run ng new once I didn’t want to install Node and the Angular CLI om my machine, so I tried to install the Angular CLI within a Docker container and it was surprisingly easy.

So first I created an empty directory on my machine and created a file docker-run-node.sh in it.

#!/usr/bin/env bash

docker run --rm -ti \
        -p 4200:4200 \
        --volume $PWD:/app \
        --workdir /app \
        --user $(id -u):$(id -g) \
        node:lts /bin/bash

This way I have an easy and consistent way to start my container. I already forwarded port 4200, because I know I’m gonna need that.

Once the container was running, within it I ran the command to install the Angular CLI although not as a global tool.

npm install @angular/cli

Now I can run all the ng command I need as long as I prefix them with npx. So running npx ng new created the new Angular website for me. To add a component I can run npx ng g c new-component.