Kamruz Jaman - Solution Architect
27 Jan 2022
In a previous post, we introduced you to the example Sitecore Docker repository we use here at Konabos. We find the use of Docker invaluable especially during the development phase. When Sitecore introduced the official images in their container registry, the sample docker-compose files they provided included the use of Traefik, which acts as a proxy/edge router.
Traefik handles all the incoming traffic requests and routes it to the correct container. It can also handle HTTPS traffic and allows you to bind custom SSL certs (which you can generate using mkcert). This allows you to use custom domains on your local machine whilst working in a more production like environment. And if you need to use advanced browser features, such as the Geolocation API, then you need to ensure you are running under a secure context.
One of the very annoying things about the setup is during development, you don't actually want Traefik to get in the way of any errors that might occur. In a Production environment, it makes sense that the router keeps a watch on any unhealthy containers and removes them from the load balancer - you wouldn't want an unhealthy CD Server to serve errors to your site users, you want to remove the unhealthy instance and let the healthy container continue to serve traffic. However, and whilst I realise it's hard to believe, sometimes my code and configuration does not always work the first time, which causes it to throw a 500 error. This trips Traefik and causes it to remove the container from load or if bringing the instance up then your requests will fail to connect in the browser. You can usually look in the logs to find the error or stack trace, or run PowerShell terminal in the container and make an curl request back to itself. This however is not the greatest feedback loop, and as developers we prefer a more instant level of feedback. So let's go ahead and disable the Traefik healthcheck so we get our error messages back!
The default docker-compose.yml file sets Traefik dependency with a condition: service_healthy and the CM entrypoint is set to run Healthcheck.ps1 (which in turn calls /healthz/ready endpoint). Unfortunately it is not possible to remove configuration using override file, you can only add addition changes or overwrite existing ones.
We generally try to make all changes to our set up using docker-compose override files. This allows us to replace the docker-compose file more easily if we need to for an upgrade and also to more easily see the changes that we have made, in much the same way as a we create patch files. Update your docker-compose.override.yml file with the following:
services: traefik: depends_on: cm: condition: service_started cm: healthcheck: test: ["CMD", "powershell", "-command", "exit 0"]
We've now updated our Traefik dependency to only ensure the CM container started and updated our CM healthcheck to exit with 0, i.e. return healthy state.
Now when we start up the instance… Sweet sweet yellow screen of death and the actual error message!
Kamruz is a 11-time Sitecore MVP who has worked with the Sitecore platform for more than a decade and has over 20 years of development and architecture experience using the Microsoft technology stack. Kamruz is heavily involved in the Sitecore Community and has spoken at various User Groups and Conferences. As one of the managing partners of Konabos Inc, Kamruz will work closely with clients to ensure projects are successfully delivered to a high standard.