Containerized SharePoint Framework (SPFx) development using Docker + WSL2, with a Dev Container for VS Code.
Dockerfilebuilds a Node 22 image withpnpmand runs the SPFx dev server.docker-compose.ymlwires ports, volumes, and environment for local dev..devcontainer/devcontainer.jsonuses the compose file so VS Code can attach a full dev environment.
- Windows 11/10 with WSL2 enabled.
- Docker Desktop with WSL2 integration enabled for your distro.
- VS Code with the "Dev Containers" extension.
Optional but recommended:
- Git in WSL.
- Node tooling on the host only if you want to run outside containers.
Recommended layout:
- Clone the repo inside your WSL2 filesystem (e.g.
~/code/spfx-container). - Open that folder in VS Code using the WSL extension (Remote - WSL).
- Reopen in container when prompted (or run "Dev Containers: Reopen in Container").
Why: bind mounts are faster and more reliable when the source is inside WSL rather than on C:\.
This repo is set up for VS Code Dev Containers:
.devcontainer/devcontainer.jsonpoints todocker-compose.yml.- The container exposes:
4321(SPFx dev server)35729(live reload)
- The container mounts the workspace and a
node_modulesvolume to avoid Windows/WSL conflicts.
To start:
- Open the repo in VS Code (from WSL path).
- Run "Dev Containers: Reopen in Container".
- In the container terminal:
npm installnpm run start
Dockerfile:
- Base image:
node:22 - Installs
pnpmglobally. - Copies
package.json(install step is optional). - Copies the repo.
- Exposes
4321and35729. - Runs
npm run startby default.
If you want deterministic installs, add a pnpm-lock.yaml and update the Dockerfile to copy it and run pnpm i --frozen-lockfile.
docker-compose.yml:
- Builds the image from
Dockerfile. - Maps ports
4321and35729. - Mounts:
- Workspace to
/usr/app - Anonymous volume for
/usr/app/node_modules ${USERPROFILE}/.gcbto/root/.gcbfor SPFx dev certs (adjust if needed)
- Workspace to
- Sets
NODE_ENV=development.
To run manually without VS Code:
docker compose up --buildThen open:
- https://localhost:4321 (SPFx dev server)
- Slow or broken bind mounts: move the repo into WSL (
/home/<user>/...), notC:\. - Docker Compose validation errors: ensure
docker-compose.ymlhasbuildonly for build options, andimage/ports/volumes/envat the service level. - Missing
.gcbdirectory: run SPFx cert setup in the container or adjust the mount to your cert location.
From the dev container:
npm install
npm run start