Test typescript compiler image
71
My first image test...
steveedwards/test-image-ts is a Docker learning project that uses Node.js and globally install typescript in order to provide typescript compilation. The container maps a shared volume to the local machine running Docker. In the container, the files are arbitrarily stored in /tmp/container/scratch-typescript. This helps me differentiate between where the code is running.
FROM node
RUN npm -g install typescript
CMD ["/usr/local/bin/tsc", "-v"]
docker build -t steveedwards/typescript .
To test that tsc installed properly run the default command:
docker run -it --rm steveedwards/typescript
It should return a version, which is the tsc version.
If NFS is in use, the consider using /tmp or another partition that is not on NFS as some permission issues might occur when the container tries to share a files located on NFS.
In order to avoid NFS permission issues, the examples use the /tmp/dockerhost/scratch-typescript directory on the Docker host.
On the Docker host change to the working directory that will be used to compile typescript and create a tsconfig.json file.
cat > tsconfig.json
{
"compilerOptions": {
"target": "es5",
"experimentalDecorators": true
}
}
Run the watch compiler:
docker run -it --rm -v /$PWD:/tmp/container/scratch-typescript/ steveedwards/test-image-ts /bin/bash -c "cd /tmp/container/scratch-typescript && tsc -w"
Any *.ts files modified on the Docker host will be compiled to javascript of the version specified in the tsconfig.json file.
If the Dockerfile default command is set to run tsc -w, the container will need to be stopped from the Docker host with the docker stop command. So for now, the default command is just set to return the typescript version with tsc -v.
docker stop <image>
Create app.ts in the typescript working directory.
var todo:string = "Pick up drycleaning";
console.log( `Don't forget to ${todo}`);
The compiler should create app.js which can be run with the same node based container.
docker run -it --rm -v $PWD:/tmp/container/scratch-typescript/ test-image-ts /bin/bash -c "cd /tmp/container/scratch-typescript && node app.js"
Content type
Image
Digest
Size
266.2 MB
Last updated
over 8 years ago
docker pull steveedwards/test-image-ts:v0.0.1