> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://cla-demo.postmansolutions.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://cla-demo.postmansolutions.com/_mcp/server.

# 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

1. Open Visual Studio Code.
2. Display the Terminal.
3. Create a working directory.

```bash
mkdir ~/node-docker-app
cd ~/node-docker-app
```

4. Pull the Node LTS image from Docker.

```bash
docker image pull node:lts
```

5. Run the container.

```bash
docker run -it -v `pwd`:`pwd` -w `pwd` -p 127.0.0.1:3000:4000 node:lts sh
```

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.

6. Initialize the node project.

```bash
npm init -y
```

7. Install Fastify and Typescript dependencies

```bash
npm install fastify
npm install --save-dev typescript ts-node @types/node
```

8. In VS Code, select `Explorer` then click `Open Folder`. When prompted select the directory that was created `node-docker-app`.
9. Verify that package.json, package-lock.json, and node\_modules folder are present.
10. Create a tsconfig.json file in the root directory:

```
{
  "compilerOptions": {
    "target": "ES6",
    "module": "CommonJS",
    "strict": true,
    "outDir": "dist",
    "rootDir": "src",
    "esModuleInterop": true
  }
}
```

11. In Explorer or Terminal create a `src` folder and create file: `server.ts` and add the following:

```
import Fastify from "fastify";

const fastify = Fastify({ logger: true });

// Define a route
fastify.get("/", async (request, reply) => {
  return { message: "Hello from Fastify + TypeScript inside Docker (Alpine)!" };
});

// Start the server
const start = async () => {
  try {
    await fastify.listen({ port: 4000, host: "0.0.0.0" });
    console.log("Fastify TypeScript server running on port 4000");
  } catch (err) {
    fastify.log.error(err);
    process.exit(1);
  }
};

start();
```

12. Run the server inside the docker container.

```
npx ts-node src/server.ts
```

13. Test the API route:

```bash
curl http://127.0.0.1:3000
```

14. Verify that the following is displayed:

```
~/code/node-docker-app$ curl http://127.0.0.1:3000
{"message":"Hello from Fastify + TypeScript inside Docker (Alpine)!"}
```