My local Sitecore JSS + Docker setup

Jack Spektor
3 min readMay 23, 2020

Recently I was trying out latest Sitecore Javascript Services framework.

In summary — its an SDK for Sitecore that allows to build Javascript apps with Sitecore without any need for BE development.

You can learn more about it here:

https://jss.sitecore.com/

At the same time I was very interested in Sitecore Docker images so I’ve decided to kill two birds with one stone and do my research of JSS with Docker.

https://github.com/Sitecore/docker-images

The goal of my investigation was to be able to setup a Sitecore JSS instance in Docker and publish my local JSS app there.

Here I’ll describe some issues that I faced as part of my setup and how to solve them.

CORS settings

As my Sitecore Docker is running on my local instance and alongside my IIS instance it meant that I had to choose port different to 80 and as a result my request URL was different to one that Sitecore JSS was expected.

By default Sitecore Docker hosts Sitecore instance behind 80 port so I had to add additional binding to make sure that my local and exposed docker ports match.

Another way to solve CORS exceptions could be to configure API key allowed origins in Sitecore to *

This way it would accept ALL urls and controllers, but make sure this configuration is configured only for local instance as its a bad security practice

Host bindings

By default Sitecore Docker image is binding Sitecore instance to localhost port number.

In my case I wanted to make sure I can access Sitecore instance using custom hostname locally.

For that Docker allows you to configure custom startup script to configure custom IIS bindings.

docker-compose.yml snippet

Note the ServiceMonitor.exe that we are copying on startup. The reason why I’m doing this is because of known Docker bug when running JSS, which was fixed in later versions of IIS images, so if you are running with something later than ltsc2019 image — you should be ok.

Docker startup script

Volume bindings

Another challenge when I was deploying was to copy the configs that were generated by Sitecore JSS to Docker instance.

One way to do that is to setup the robocopy script as described here:

https://intothecloud.blog/2019/09/21/Deploying-and-Debugging-Your-Visual-Studio-Solution-to-Your-Sitecore-Docker-Containers/

I decided to go other way though and setup a few volume bindings for this:

  • cm_patches, cd_patches — binded to the App_Config/zzzPatches folder
  • build — binded to the wwwroot/dist/my-first-jss-app folder

Thus artifacts that were generated by my JSS script were instantly updated in Docker

Full example with docker-compose.yml can be found here:

https://github.com/JackTheHack/Sitecore.JSS.Docker.Template

--

--

Jack Spektor

Sitecore MVP 2018–2020, Sitecore Developer in AKQA, traveler and lover of life.