官术网_书友最值得收藏!

Inspecting container logs

Accessing the main process' standard output and standard error logs in the container is crucial for debugging issues with containerized applications. This is also a common scenario when using Kubernetes, where you can perform similar operations using Kubernetes CLI tools.

The current architecture of the official Microsoft IIS Docker image does not provide any logs to the stdout of ServiceMonitor.exe (the main process in the container), so we will demonstrate this on the simple ping.exe example that we used previously. Run the following container in order to create the container:

docker run -d --rm --isolation=process mcr.microsoft.com/windows/nanoserver:1903 cmd /c ping localhost -n 100

Now, in Visual Studio Code, you can inspect the logs by opening the Command Palette (Ctrl + Shift + P) and executing the Docker: Show Logs command. After selecting the container name, the logs will be shown in the terminal. Alternatively, you can use the Docker Explorer tab, expand the Containers list, right-click the container you want to inspect, and select Show Logs:

This will open a terminal in Visual Studio Code so that you can start streaming logs from the container's stdout and stderr instances.

For the PowerShell command line, you have to use the docker logs command:

docker logs <containerId>

It is also worth noting that in debugging scenarios, you may find the -f and --tail parameters useful:

docker logs -f --tail=<number of lines> <containerId>

The -f parameter instructs the log output  to be followed in real-time, whereas the --tail parameter makes it possible to show only a specified number of last lines from the output.

Apart from inspecting container logs, you will often need to exec into a running container. This will be covered in the next subsection.

主站蜘蛛池模板: 始兴县| 怀远县| 阿鲁科尔沁旗| 尚志市| 兴国县| 乌兰察布市| 肥乡县| 黄石市| 招远市| 汶川县| 格尔木市| 揭东县| 新安县| 铁岭市| 广南县| 南和县| 望城县| 民勤县| 乌兰浩特市| 涪陵区| 乌兰浩特市| 那坡县| 永寿县| 太康县| 师宗县| 阿尔山市| 焦作市| 眉山市| 塔城市| 长海县| 铜鼓县| 紫阳县| 巩留县| 工布江达县| 依兰县| 鄂尔多斯市| 东港市| 梅河口市| 逊克县| 东海县| 卢龙县|