After using Docker Compose to start Sitecore 10 with Docker it appeared that the traefik and cm containers were unhealthy when viewing the containers using the docker ps command
After some investigation I noticed the following error and it turned out that the Sitecore.Master database was not attached at all despite all of the other databases being in position
Exception: System.Data.SqlClient.SqlException
Message: Cannot open database "Sitecore.Master" requested by the login. The login failed.
This is easy to spot if you use the docker logs command.
docker logs --tail 100 {container id}
The mdf and ldf files were in place in the container but they appeared to be corrupt. This is not necessarily a problem because the getting started guide (https://www.sitecore.com/knowledge-center/blog/359/getting-started-as-a-developer-4499) comes with all of the databases which are held in getting-started/mssql-data
My initial attempts led me to the following error which would not allow me to copy to the container
Error response from daemon: filesystem operations against a running Hyper-V container are not supported
This was resolved by stopping and starting the container before and after copying the files
docker stop {container id}
docker cp C:\sitecore\docker\getting-started\mssql-data\Sitecore.Master_Primary.mdf sitecore-xp0_mssql_1:/data
docker cp C:\sitecore\docker\getting-started\mssql-data\Sitecore.Master_Primary.ldf sitecore-xp0_mssql_1:/data
docker start {container id}
Once the files are copied you can check they are in place using the following command to open up an interfactive powershell session
docker exec -it {container id} powershell
Unfortunately after attempting to attach the database in SQL Server Management studio I kept receiving the following error.
Unable to open the physical file "C:\test\Sitecore.Master_Primary.mdf". Operating system error 5: "5(Access is denied.)".
CREATE DATABASE failed. Some file names listed could not be created. Check related errors. (Microsoft SQL Server, Error: 5120)
To resolve this you need to use c:/data which contains the other databases