Docker images for SharePoint Framework
50K+
Docker images for running the SharePoint Framework development environment.
This README covers the latest SharePoint Framework version. For instructions for other versions, see the versioned docs folder on GitHub.
~/.rushstack once first — see Trusting the development certificate for details
docker run -it --rm --name ${PWD##*/} -u node -p 4321:4321 -p 35729:35729 -v "$PWD":/usr/app/spfx -v ~/.rushstack:/home/node/.rushstack m365pnp/spfx:latest
In fish, replace ${PWD##*/} with (basename $PWD).
docker run -it --rm --name (Split-Path -Leaf $PWD) -u node -p 4321:4321 -p 35729:35729 -v "${PWD}:/usr/app/spfx" -v "${HOME}\.rushstack:/home/node/.rushstack" m365pnp/spfx:latest
docker run -it --rm --name spfx-helloworld -u node -p 4321:4321 -p 35729:35729 -v "%cd%":/usr/app/spfx -v "%USERPROFILE%\.rushstack":/home/node/.rushstack m365pnp/spfx:latest
After the container starts, you can work with it the same way you would work with SharePoint Framework installed on your host. To create a new SharePoint Framework project in the container command line execute:
yo @microsoft/sharepoint
All files scaffolded by the generator will be stored in your project directory on your host from where you can commit them to source control.
The .rushstack mount keeps the development certificate on your host, so it survives --rm and only has to be trusted once.
On Linux or WSL, before starting the container the first time, create the folder that stores the certificate. If Docker creates it instead, it's owned by root and the container can't write to it:
mkdir -p ~/.rushstack
The first heft start creates a certificate authority in the .rushstack folder of the home directory mounted into the container. That's the home of the shell you ran docker run from. Add it to your trusted root certificates using the command for that shell:
WSL prompt (installs into the Windows certificate store):
certutil.exe -user -addstore Root "$(wslpath -w ~/.rushstack/rushstack-ca.pem)"
PowerShell prompt (installs into the Windows certificate store):
certutil -user -addstore Root "$HOME\.rushstack\rushstack-ca.pem"
macOS Terminal (installs into your login keychain):
security add-trusted-cert -r trustRoot -k ~/Library/Keychains/login.keychain-db ~/.rushstack/rushstack-ca.pem
Restart the browser so it picks up the trusted certificate.
Before running heft start, edit config/serve.json in your project so the dev server listens on all interfaces. By default it listens on localhost inside the container, which the published ports can't reach. Add ipAddress, and remove hostname (since it takes precedence over ipAddress) as follows:
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/spfx-serve.schema.json",
//...
"ipAddress": "0.0.0.0"
}
From here, you run the usual npm and heft commands at the container prompt, exactly as you would with SPFx installed on your host. Edit the project files on your host, since they're shared with the container, and open the workbench in your host browser, since ports 4321 and 35729 are published to it.
To close the container, run the following command from the container prompt:
exit
You can also use this image to build an environment for Visual Studio development containers
To build the image from this repository instead of pulling it from Docker Hub:
docker buildx build . --target default --load --tag my-spfx
--load puts the image in your local image store so docker run can find it. Then start it with the command from Usage for your shell, replacing m365pnp/spfx:latest with my-spfx. For example, in a POSIX shell:
docker run -it --rm --name ${PWD##*/} -u node -p 4321:4321 -p 35729:35729 -v "$PWD":/usr/app/spfx -v ~/.rushstack:/home/node/.rushstack my-spfx
When running yo @microsoft/sharepoint you get an error that the container is unable to write files to the disk. In most cases this is caused by the drive not being shared in Docker. Go to Docker > Settings > Sharing to enable sharing the drive where your project is located.
When using the container with SharePoint Framework >=v1.14.0, you can't access the local workbench or can't load bundles in the hosted workbench. This is caused by the default mapping of the workbench to localhost, which isn't accessible outside of the container. To fix it, map the workbench to 0.0.0.0, by modifying the ./config/serve.json file in your SharePoint Framework project to:
{
"$schema": "https://developer.microsoft.com/json-schemas/core-build/serve.schema.json",
//...
"ipAddress": "0.0.0.0"
}
If serve.json also contains a hostname property, remove it: it takes precedence over ipAddress. Keep browsing to https://localhost:4321 from the host.
When using the container with SharePoint Framework >=v1.6.0, you can't access the local workbench or can't load bundles in the hosted workbench. This is caused by the default mapping of the workbench to localhost, which isn't accessible outside of the container. To fix it, map the workbench to 0.0.0.0, by modifying the ./config/serve.json file in your SharePoint Framework project to:
{
"$schema": "https://developer.microsoft.com/json-schemas/core-build/serve.schema.json",
//...
"hostname": "0.0.0.0"
}
Modify node_modules\@microsoft\spfx-heft-plugins\lib\plugins\webpackConfigurationPlugin\WebpackConfigurationGenerator.js:393
const debugBaseUrl = `${serveConfig.https ? 'https' : 'http'}://${serveConfig.hostname || 'localhost'}:${serveConfig.port || 4321}/${distFolderName}/`;
to:
const debugBaseUrl = `${serveConfig.https ? 'https' : 'http'}://localhost:${serveConfig.port || 4321}/${distFolderName}/`;
Modify node_modules\@microsoft\spfx-heft-plugins\lib\plugins\webpackConfigurationPlugin\WebpackConfigurationGenerator.js:376
const debugBaseUrl = `${serveConfig.https ? 'https' : 'http'}://${serveConfig.hostname || 'localhost'}:${serveConfig.port || 4321}/dist/`;
to:
const debugBaseUrl = `${serveConfig.https ? 'https' : 'http'}://localhost:${serveConfig.port || 4321}/dist/`;
When using the container with SharePoint Framework >=v1.6.0 on Windows, you can't access the local workbench despite following the steps from the previous section. This has to do with Windows being unable to correctly access 0.0.0.0. To fix it, first, modify config\write-manifests.json to (add the debugBasePath property):
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/write-manifests.schema.json",
"cdnBasePath": "<!-- PATH TO CDN -->",
"debugBasePath": "https://localhost:4321/"
}
Then, open node_modules\@microsoft\sp-build-web\lib\SPWebBuildRig.js and change lines from:
spBuildCoreTasks.writeManifests.mergeConfig({
debugBasePath: `${serve.taskConfig.https ? 'https' : 'http'}://${serve.taskConfig.hostname}:${serve.taskConfig.port}/`
});
to (add the if statement):
if (!spBuildCoreTasks.writeManifests.taskConfig.debugBasePath) {
spBuildCoreTasks.writeManifests.mergeConfig({
debugBasePath: `${serve.taskConfig.https ? 'https' : 'http'}://${serve.taskConfig.hostname}:${serve.taskConfig.port}/`
});
}
Depending on the SPFx version the lines to replace are different:
| SPFx version | SPWebBuildRig.js lines to replace |
|---|---|
| 1.6.0, 1.7.0 or 1.7.1 | 83-85 |
| 1.8.0, 1.8.1 or 1.8.2 | 88-90 |
| 1.9.1 | 92-94 |
| 1.10.0 or 1.11.0 | 96-98 |
Windows 10 Anniversary Update and Windows Server 2016 have native support for containers. At this moment Windows supports only containers built on Windows Server Core or Nano Server and you won't be able to run this container natively on Windows. Instead you should use Docker for Windows or Docker Toolbox.
Content type
Image
Digest
sha256:ad96317dd…
Size
492.5 MB
Last updated
1 day ago
docker pull m365pnp/spfxPulls:
487
Last week