- Hands-On Kubernetes on Windows
- Piotr Tylenda
- 380字
- 2021-06-24 16:54:00
Exec into a running container
In debugging and testing scenarios, it is often required to execute another process inside a running container in an ad hoc manner. This is especially useful for creating a shell instance (for Windows, with cmd.exe or powershell.exe, and for Linux, with bash or sh) in the container and interactively debugging the container. Such an operation is called performing exec into a running container.
Visual Studio Code enables this through Docker Explorer. In the Docker Explorer tab, find the container you would like to exec into, right-click it, and choose Attach Shell:
In the Powershell command line, the equivalent docker exec command is as follows:
docker exec -it <containerId> powershell.exe
The preceding command creates a new powershell.exe process inside the running container in interactive mode with the attached terminal (the -it parameter). As you can see, a new interactive instance of the Powershell terminal opens:
Let's try inspecting the contents of index.html inside the container's working directory:
cat .\index.html
The following screenshot shows the output of the preceding command:
This reveals the expected contents of the index.html file that we created and added to the image earlier.
We can also inspect the IIS worker process (w3wp.exe) for the application pool hosting index.html. This is a common scenario during debugging when not all the logs are available directly via container output logs:
cat ..\logs\LogFiles\W3SVC1\u_ex<current date>.log
The following screenshot shows the output of the preceding command:
Using docker exec is one of the most powerful commands that you have in your container toolbox. If you learn how to use it, you'll be able to debug your applications almost as if they were hosted in a non-containerized environment.
- WildFly:New Features
- Python程序設(shè)計教程(第2版)
- Mastering JavaScript Functional Programming
- Java高并發(fā)核心編程(卷2):多線程、鎖、JMM、JUC、高并發(fā)設(shè)計模式
- PowerCLI Cookbook
- Java:Data Science Made Easy
- 深入理解Java7:核心技術(shù)與最佳實踐
- Mastering Linux Network Administration
- Mastering Android Development with Kotlin
- JavaScript程序設(shè)計(第2版)
- Flowable流程引擎實戰(zhàn)
- Node.js開發(fā)指南
- PHP與MySQL權(quán)威指南
- 從Excel到Python數(shù)據(jù)分析:Pandas、xlwings、openpyxl、Matplotlib的交互與應(yīng)用
- Learning Ionic