Skip to content

Instantly share code, notes, and snippets.

@ahmedazhar05
Last active July 13, 2023 08:52
Show Gist options
  • Save ahmedazhar05/28f65c34ec511f07fa8ed6878c6a65d7 to your computer and use it in GitHub Desktop.
Save ahmedazhar05/28f65c34ec511f07fa8ed6878c6a65d7 to your computer and use it in GitHub Desktop.
Docker image configuration for on-the-go TypeScript
FROM node:latest
ARG UID
ARG GID
RUN apt update -y \
&& apt upgrade -y
USER $UID:$GID
RUN mkdir -p "$HOME/.npm-global" \
&& npm config set prefix "$HOME/.npm-global" \
&& npm install -g npm@latest \
&& npm install -g typescript
WORKDIR /workspace
# $HOME=/home/node automatically once you set the instruction USER <UID>[:<GID>]
ENTRYPOINT ["/home/node/.npm-global/bin/tsc"]
@ahmedazhar05
Copy link
Author

Build command:

$ docker build --rm --build-arg UID=`id -u` --build-arg GID=`id -g` --tag tsc - < Dockerfile

Set alias in bash

$ alias tsc='docker run --rm --user `id -u`:`id -g` -v $PWD:/workspace tsc'

Now you can run typescript from anywhere

$ tsc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment