2 min read

Fixing Sitecore databases running in Docker - Windows 11

It has been a while - over a year - since I ran my Sitecore docker projects locally. I was working on other projects for which we don't have a local docker development environment (yet?).

In the mean time my Windows version updated to Windows 11, Docker had a newer version and I wanted to get started again with a Sitecore 10.1 project...

The problem

Unfortunately, my Docker traefik container didn't start. Looking at the logs for all containers, CM could not connect to any database. Although the correct data folder was mounted.

So ... looking at the mssql container and its logs showed the following:

Cannot detach a suspect or recovery pending database. It must be repaired or dropped.

And no connection to any database was possible:

8/9/2022 10:29:49 AM ...ureAudit Login failed for user 'sa'. Reason: Failed ...

Looking at logs of CM, similar messages could be found:

Exception: System.Data.SqlClient.SqlException
Message: Cannot open database "Sitecore.Reporting" requested by the login. The login failed.
Login failed for user 'sa'.
Source: .Net SqlClient Data Provider

The investigation

Alright, so no databases can be used, CM can't start and traefik fails.

Let's connect to the SQL server first.

  • docker ps to see all containers
  • docker inspect guid-of-sql to list the low level information of a container, and the IP that you can use to reach it
  • In the returned NetworkSettings > Networks, look at the IPAddress:
  • Or if you only want to see the IP address do the following:
    docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' guid-of-sql-container
  • Open MSSMS, connect to the IP and use the SQL user and password defined in your .env file.
  • Upon opening, I saw that basically all databases are 'Recovery Pending'... ugh

The solution - I thought

Well this one is a bit akward :-(

I was not able to repair the recovery pending databases. Online solutions I found were to set the database in Emergency mode and to run a CheckDB command. (reference
https://dbamohsin.wordpress.com/2012/01/23/cannot-detach-a-suspect-or-recovery-pending-database/ )

It failed for me.

The solution - I thought part 2

Ok, lets just try with fresh clean empty databases.

Emptied my mssql data folder and ran the docker containers again. This time the fresh databases were created but the CM was still not able to get up and running.

I checked my docker-compose file and the mssql image in use was the following:

${SITECORE_DOCKER_REGISTRY}sitecore-xp0-mssql:10.1-ltsc2019

I'm not sure why, but changing it to 20H2 version, resulted in less errors in my log files. No more connection issues towards the default databases... except for the shard databases.

The final solution

I found some answers in this stackexchange post: https://sitecore.stackexchange.com/a/31589/483

The problem wasn't that my Shard databases weren't created but the Password I used was too weak and the SQL server didn't accept weak passwords.

Luckily you can change the password in your .env file. I updated it to a more complex value, docker-compose up everything and it worked.