Windows containers & SQL Server – Part 3 – Error Logs

So far this series has covered: installing Docker for Windows, the basic commands for managing images and containers, and creating a new image. This post will cover troubleshooting containers & the Docker application using the various log files that are available.

Depending on the type of process being run in a container (interactive or non-interactive), event and error information may be collected by the host logs, application logs, or by the Docker logs (or by all 3, in the case of SQL Server and IIS for Windows).

Host Logs

The Windows Application & System Logs will collect event information about the Docker application & host system. These events can be viewed by:

  1. Open the Windows Event Viewer application.
  2. Expand the Windows Logs folder and select the Application or System log.
  3. Select Filter Current Log from the Actions list, and then expand the dropdown and select docker.

Application Logs

For containers that are running non-interactive processes (ie. SQL Server or IIS for Windows), the application will send event information to its own log file in the container. These logs can typically be accessed:

  • through the application itself (ie. using SQL Server Management Studio).
  • by opening an interactive PowerShell session to the container.
  • copying the log file out of the container.

Viewing logs with SSMS

To view the SQL Server Error Log:

  1. Open SQL Server Management Studio.
  2. Connect to the SQL Server container using the hostname and port. (in this example the container is on the local computer, using port 1433)
  3. Expand the Management and SQL Server Logs folders.
  4. Double-click on the desired log file to open.

Opening logs with an interactive PowerShell session

If SSMS is unable to open the log files in the container, it may be necessary to create an interactive session (to the container) using PowerShell. To create an interactive session:

  1. Open Powershell (an Administrator PowerShell window may be necessary).
  2. Verify that the container is running normally:
    docker ps -a
  3. Connect to the container:
    docker exec -it <container name or ID> powershell
  4. Browse to the log file directory and open the log file using the type command (type is an alias for Get-Content).
    cd C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\MSSQL\Log
    type .\ERRORLOG

With larger log files the type command can be cumbersome to use without a known filter criteria. In this situation it may be easier to copy the file out of the container and open the log file with a more robust text editor.

Copying log files out of a container

The docker cp command can be used to copy files between the container and host file systems. The cp command requires the name or ID of a container, along with the folder or file paths for both the host and container. The syntax for the cp command is:
docker cp <container name or ID>:<source path> <destination path>
Depending on whether the container name is part of the source path or destination path, files can be copied into or out of the container.

Once the log file has been copied to the host, it can then be opened with any preferred application or editor (eg. Notepad ++).

While the cp command works fine with Windows Server based containters, it does not appear to work with containers running in Docker Desktop for Windows.

In this situation, a directory on the host can be mounted as a volume in the container, and then the log files can be copied into that.

Docker Logs

The last set of logs to look at are for containers with interactive processes. These can be displayed using the Docker Logs command and contain any outputs that are sent to STDOUT (Standard Output) or STDERR (Standard Error). If the log output is too long, the option –since <date> may be helpful for limiting the log output to the newest entries.
docker logs <container name or ID> --since 2020-08-29

Leave a Reply

Your email address will not be published. Required fields are marked *