Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

Coder template: docker-nodejs-sample

This folder is a Coder template that spins up a ready-to-code cloud workspace for this app. Each workspace gives you:

  • VS Code in the browser (code-server) to write code
  • The app cloned and npm install-ed for you
  • PostgreSQL running inside the workspace (no separate DB to manage)
  • The running app reachable from your laptop at http://localhost:5173

You don't need to know Terraform to use it. Follow the steps below.


Prerequisites

  1. Docker — installed and running. (Get Docker) Workspaces run as Docker containers, so the Docker daemon must be up.
  2. That's it — the next step installs Coder itself.

1. Install the Coder CLI

macOS / Linux:

curl -fsSL https://coder.com/install.sh | sh

(Windows and other options: https://coder.com/docs/install.)

Verify it's installed:

coder version

2. Start a local Coder server

In its own terminal (leave it running):

coder server

The first time, it prints a URL like http://localhost:3000 and walks you through creating the first admin user in your browser. Keep this terminal open — it is your Coder server.

Already have a Coder server? Skip this step and just point coder login at it.


3. Log in from a second terminal

coder login http://localhost:3000

This opens a browser to grab a session token; paste it back at the prompt.


4. Push this template to Coder

From the repository root (the folder that contains this coder/ directory):

coder templates push docker-nodejs-sample -d ./coder -y

This uploads the template and validates it. You only do this once (and again whenever the template files change).


5. Create a workspace

coder create dev1 --template docker-nodejs-sample

dev1 is just a name — call it whatever you like. The build takes a couple of minutes the first time (it builds the workspace image, starts Postgres, clones the repo, and runs npm install).

By default it clones https://github.com/BrandonDenham/docker-nodejs-sample-coder. To use a different repo or branch, add --parameter "repo_url=<url>" --parameter "repo_branch=<branch>".


6. Open it and run the app

  1. Open the workspace in the Coder dashboard (the URL from step 2) and click code-server to get VS Code in your browser.

  2. In code-server's terminal, start the dev server:

    cd ~/docker-nodejs-sample
    npm run dev
  3. On your own machine, open http://localhost:5173.

That's the live app, with hot-reload. The frontend talks to the API on port 3000 and to PostgreSQL — all inside the workspace — automatically.


How it fits together

Piece Where it runs How you reach it
code-server (IDE) workspace container, port 13337 code-server button in the dashboard
Vite dev server (frontend) workspace container, port 5173 http://localhost:5173 on your machine
Express API workspace container, port 3000 internal — Vite proxies /api to it
PostgreSQL workspace container, port 5432 internal — the app connects automatically

Your code, installed dependencies, and the database all live on a persistent volume, so they survive stopping and restarting the workspace.


Useful commands

coder list                      # see your workspaces
coder ssh dev1                  # shell into the workspace
coder stop dev1                 # stop (saves resources; data persists)
coder start dev1                # start it back up
coder delete dev1               # remove the workspace
coder port-forward dev1 --tcp 5173:5173   # alternative way to reach the app

Customizing

  • Use a different repo / branch: change the --parameter values in step 5, or edit the defaults in coder/main.tf (repo_url, repo_branch).
  • Port 5173 already in use on your machine? Only one running workspace can bind it at a time. Stop the other workspace, or use the coder port-forward command above to map to a different local port.

Notes

  • localhost:5173 works because the workspace publishes its Vite port straight to your host. Coder's normal subdomain-based app proxy needs a wildcard DNS domain, which a local localhost server can't provide — so we expose the port directly.
  • For production-style serving instead of the dev server, you can build and run inside the workspace with npm run build && npm start (serves on port 3000).