Docker Development
This demonstrates usage of the Linux VM with a Docker environment using a sample app.
Pre-requisite
Run script to connect to Linux VM via SSH. Use linuxVMConnectionSetup-SEA or linuxVMConnectionSetup script depending on VM location. Ensure that connection is successful.
Steps
- Open Visual Studio Code.
- Display the Terminal.
- Create a working directory.
- Pull the Node LTS image from Docker.
- Run the container.
This command does the following:
- Starts a Node.js Alpine container.
- Provides interactive shell access (sh) inside the container.
- Mounts the current project directory into the container so changes persist.
- Ensures that files created inside the container appear on the VM.
- Maps port 4000 in the container to 3000 on the VM, but only accessible locally (127.0.0.1).
[!NOTE] The port mapping is needed to call the API later.
- Initialize the node project.
- Install Fastify and Typescript dependencies
- In VS Code, select
Explorerthen clickOpen Folder. When prompted select the directory that was creatednode-docker-app. - Verify that package.json, package-lock.json, and node_modules folder are present.
- Create a tsconfig.json file in the root directory:
- In Explorer or Terminal create a
srcfolder and create file:server.tsand add the following:
- Run the server inside the docker container.
- Test the API route:
- Verify that the following is displayed: