TypeScript in Docker
| The Node image | |
| Run one-liners | |
| Compile inside the container | |
| Mount your project |
The Node image
TypeScript runs on Node, so start from Node even inside Docker. The node image ships Node plus npm, and the node:22 tag pins the long term support line used in this course.
No local Node install is needed for this route because the container brings its own runtime. Install Docker first with its normal setup flow, then pull nothing by hand since Docker fetches the image on first use.
Run one-liners
Try a throwaway container that prints the Node version and exits. The rm flag removes the container when the command finishes:
docker run --rm node:22 node -v
v22.5.1
A version line means Docker works and the image is ready. Replace the version flag with other Node flags later to probe the runtime.
Compile inside the container
Compile with npx tsc inside the same image. Mount makes local files visible to the container, so the compiler reads the project folder and writes output back to it. The pattern is always mount plus npx tsc as plain text steps:
docker run --rm node:22 npx -y tsc --version
Version 5.4.5
A version line means the TypeScript package resolved inside the container. Any recent version works for the lessons in this course.
Mount your project
The v flag maps the current folder to /app inside the container, while the w flag sets /app as the working folder. In words the pattern is minus v, double quoted current folder marker, colon, app path, minus w, app path.
Run the compiler from the project root so relative paths resolve the same way as a local install:
docker run --rm -v "$PWD":/app -w /app node:22 npx tsc --version
Version 5.4.5
Change the tail after the image name to compile a real project, for example npx tsc with no flags when a config file is present. Remove the container after each run and keep sources only on the host.
Next: TypeScript course
Article author: Arthur Isaev