Creating a Docker Container Environment with Sitecore XM and Next.js

Director, Sitecore Practice
  • Twitter
  • LinkedIn


With Sitecore s transformation to composable DXP and their recent release of the Next.js SDK, I thought I would set up a docker container environment with Sitecore XM and Next.js for learning purposes. It turns out, Sitecore's guide was very straightforward. For the XM topology, we only needed to change the init.ps1 step. For completeness, I've included all the steps here.

Verifying / Installing prerequisites

  1. Powershell 5.1 - comes bundled with Windows 10, but to verifyIn cmd, run
  2. powershell
  3. Run
  4. $PSversionTable
  5. .Net Core 3.1Download and install .Net 3.1
  6. Verify: In cmd,
  7. run dotnet version
  8. .Net Framework 4.8Download and install .Net Framework 4.8
  9. Verify: In Powershell run
  10. (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full").Release -ge 528040
  11. If it returns true, that means 4.8 is installed. More info on
  12. how to determine .Net Framework version
  13. Download and install dockerRun Docker Desktop
  14. Switch to windows containersOpen the windows system tray, and right click on Docker Desktop
  15. Click "Switch to windows containers "
  16. Node.jsFor node.js, I like to use NVM for windows, which will allow you to easily switch node versions
  17. To use NVM, uninstall any pre-existing node installations
  18. Download NVM for windows
  19. To use node ltsInstall lts:
  20. nvm install lts
  21. Switch to lts:
  22. nvm use lts
  23. Sitecore templateInstall Sitecore template:
  24. dotnet new -i Sitecore.DevEx.Templates --nuget-source https://sitecore.myget.org/F/sc-packages/api/v3/index.json

Stop services

In order to run docker, ports 443 and 8984 must be free.

  1. Stop port 443, stop IIS by running
  2. iisreset /stop
  3. Stop any Solr services running on port 8984In powershell, check what's using the port by running
  4. Get-Process -Id (Get-NetTCPConnection -LocalPort 8984).OwningProcess
  5. If you get the error, there's nothing running on port 8984 and you're good to go.
    Get-NetTCPConnection : No MSFT_NetTCPConnection objects found with property 'LocalPort' equal to '8984'. Verify the value of the property and retry.
  6. If you need to stop the servicerun
  7. Stop-Service -Name "the name of your service"
  8. or if using nssm, run
  9. nssm stop "the name of your service"

Installing

  1. In powershell, navigate to a directory e.g. c:\repos
  2. Run
  3. dotnet new sitecore.nextjs.gettingstarted -n XmNextJs
  4. (replace XmNextJs with your own project name)
  5. Navigate to the directory of your project e.g. XmNextJsrun
  6. .\init.ps1 -InitEnv -Topology "xm1" -LicenseXmlPath "path\to\license.xml" -AdminPassword "yourpasswordhere"
  7. The script will prompt you on how you want to configure your solution such as SSG vs SSR. I left most of this as the default
  8. Once the script finishes, run
  9. setx NODE_EXTRA_CA_CERTS C:\Users\{yourusername}\AppData\Local\mkcert\rootCA.pem
  10. Restart Powershell (or VSCode if you re using that)
  11. Run
  12. .\up.ps1
  13. The CM server will prompt you to log into sitecore - go ahead and do so using your admin credentials
  14. When the script finishes, you should be able to visit your rendering host e.g. https://www.xmnextjs.localhost/