Run a Simple Node.js Server in Docker on Ubuntu/Jetson

Run a Node.js Server in Docker (Quick Start)

In this mini-guide, you’ll install Docker, spin up a tiny Node.js server, and run it inside a container. Perfect for sanity checks on Docker, networking, and Node.js.


1) Install & Verify Docker

On Ubuntu (incl. Jetson), install Docker and run its hello-world image to confirm it works:

sudo apt update
sudo apt install -y docker.io
sudo docker run --rm hello-world

If you see the “Hello from Docker!” message, Docker is ready.

Optional (no sudo): add your user to the docker group, then log out/in:

sudo usermod -aG docker "$USER"
# log out and back in, then:
docker run --rm hello-world

2) Create a Tiny Node.js Server

Make a project folder and a simple HTTP server that responds with a greeting:

mkdir -p ~/NodeJSDemo && cd ~/NodeJSDemo
nano server.js
const http = require("http");
const server = http.createServer((req, res) => {
  res.writeHead(200, { "Content-Type": "text/plain" });
  res.end("Hello from Jetson!");
});
server.listen(3000, "0.0.0.0", () => {
  console.log("Server listening on http://0.0.0.0:3000");
});

3) Run It with Docker (no local Node.js needed)

Use the official Node image to run your script directly from the host directory:

sudo docker pull node:latest
sudo docker run --rm -p 3000:3000 \
  -v "$PWD":/usr/src/app \
  -w /usr/src/app \
  node:latest node server.js

4) Test in a Browser (or curl)

Open http://<device-ip>:3000 in a browser. You should see: Hello from Jetson!

No GUI? Use curl from another machine on the same network:

curl http://<device-ip>:3000

Optional: Package with a Dockerfile

If you prefer shipping an image instead of bind-mounting source files, add a Dockerfile:

nano Dockerfile
# syntax=docker/dockerfile:1
FROM node:18-alpine
WORKDIR /usr/src/app
COPY server.js ./
EXPOSE 3000
CMD ["node", "server.js"]

Build and run:

sudo docker build -t nodejsdemo:latest .
sudo docker run --rm -p 3000:3000 nodejsdemo:latest

Troubleshooting

Conclusion

This confirms Docker, basic networking, and Node.js all work. From here, you can grow this into a real app, add dependencies, or use the Dockerfile approach for production-grade images. For multi-service setups, explore docker compose.