Troubleshoot issues with Sitecore Docker containers

Hi, I'm Sumit
This is my blog on Sitecore, .Net and Azure
Using Docker containers with Sitecore can be challenging, especially when just starting. A lot has to do with the way we have been used to working in the IIS world, still getting used to the container intricacies and feeling lost or overwhelmed by the new ways of working. In this blog, I will try to help overcome these issues.
The Basics: Prevention is Better than Cure
To run a Sitecore environment in Docker containers, there are some fundamental steps/actions that should always be adhered to. These are generic for all the projects and imperative for a Sitecore environment to load.
Having Docker installed and running: Whether Sitecore or not, to run Docker containers, you need to have Docker installed and running.
Ensuring Windows containers are enabled: Sitecore containers use Windows containers so it is imperative that when you right-click on the Docker icon in the Windows tray, you see
Switch to Linux containersthus confirming that the Windows containers mode is active.
DNS entry is included in the Docker engine: For our Docker environment to have access to the Internet, it is important to have the DNS entry (usually
[8.8.8.8]) in the Docker engine. An example of Internet usage in the Docker context is downloadingNode.jsin the frontend build of aDockerfile. In some cases, this needs to be updated in theDeamon.json(path:C:\Users\[your username]\.docker\daemon.json) also otherwise it won't work.
IIS and Solr services are stopped: Traefik, the reverse proxy manager, does not run if the IIS is still running. So we need to ensure that it is stopped. Stopping Solr service is not a hard requirement. There is a way around it by using a different Solr port in Docker as compared to the one used in the locally configured Solr setup, if any.
No VPN running: Although there is a way to make the Docker containers work with VPN running, in most cases is better to ensure that VPN is disabled when running containers.
The Advanced: What to do when there is a problem?
Now that we have confirmed the above basics have been taken care of, what to do when there is an actual problem with a Docker container not starting up? How to resolve it?
Check the logs: As with most applications, the first thing to look at when debugging a problem is the log files. Based on the error received on starting the container, it might be useful to check the log files of the particular container.
The log file path for the
cmcontainer on the local drive is configured using thevolumesDocker keyword in thedocker-compose overridefile. For us, generally, the log file path issolution folder\docker\data\cmUsing Docker Desktop tools: Log files could be accessed directly in the Docker desktop itself. Along with the log files, there is an option to inspect the settings of the container and start a CLI if need be.

Using Docker extension for Visual Studio Code: Docker extension for Visual Studio Code could also be leveraged to check the logs, attach the shell to a terminal, and restart the container if needed

Run Docker exec: The traefik container, which acts as a reverse proxy, intercepts all the requests coming to the
cmcontainers. This has its advantages but the downside is that we do not see the actual errors occurring when there are any. The way around this is by using thedocker execcommand, which has the syntax:docker exec -it containerId powershell.exeThe entire command stands for we want to execute the containercontainerIdin an interactive mode via apowershellterminal. Once inside the container, we executeInvoke-WebRequest http://localhost -UseBasicParsingto execute a request from inside the container to see the actual error message.Run clean Sitecore instance: Another way to troubleshoot issues with our Sitecore instance is by removing our custom code/solution and running a clean Sitecore instance. Once we confirm that the Sitecore instance is running without our code, we can add our custom code to find out which config or code is the culprit.
Removing the images: There are times when we will have to rebuild the images instead of just
up.An example would be when a change is made in aDockerfilefile for one of the services. We can use the option--no-cacheoption in conjunction with theupcommand to ensure that Docker doesn't use local cache to build the image but a safer option would be to remove all the solution-specific images. Just removing the solution images means that only the images for the solution part are recreated while the stock Sitecore and Microsoft images remain intact. This approach is not only faster but also more efficient compared to removing all the images. However, if necessary, we could also opt for a more drastic measure and remove all the images using thesystem prunecommand.Docker/system restart: In the realm of IT troubleshooting, when all else fails, we adhere to a well-known adage: "Have you tried turning it off and on again?" This holds true here as well. Either a Docker restart or a complete system restart frees up memory, and clears up network glitches to name a few.
Running Sitecore in Docker containers offers many benefits in terms of portability, scalability, and development speed. However, like any technology, it can present challenges. With the troubleshooting tips and solutions provided in this blog post, you'll be better equipped to address common issues and keep your Sitecore Docker environment running smoothly. Remember to consult the official Sitecore documentation and community forums for additional guidance on specific issues and configurations. Happy Sitecore containerization!




