3.5. Debugging applications in containers
To troubleshoot container applications, you can use various command-line tools.
This is not a complete list of command-line tools. Your choice of tool depends on the container image and your use case.
Several tools, including systemctl, journalctl, ip, netstat, ping, traceroute, perf, and iostat, might need root access. They interact with system-level resources such as networking, systemd services, or hardware performance counters. Rootless containers restrict those resources for security reasons.
Rootless containers operate without elevated privileges. They run as non-root users in user namespaces. That design improves isolation from the host, limits host interaction, and reduces the attack surface.
Rootful containers run with elevated privileges. Typically they run as the root user and can access all system resources. That flexibility adds risk from privilege escalation and from exposing the host to vulnerabilities.
For more information about rootful and rootless containers, see Creating a rootless container with bind mount by using the podman RHEL system role and Special considerations for rootless containers.
- Systemd and Process Management Tools
-
systemctl: Controls systemd services within containers, allowing start, stop, enable, and disable operations.journalctl: Views logs generated by systemd services, aiding in troubleshooting container issues. - Networking Tools
-
ip: Manages network interfaces, routing, and addresses within containers.netstat: Displays network connections, routing tables, and interface statistics.ping: Verifies network connectivity between containers or hosts.traceroute: Identifies the path packets take to reach a destination, useful for diagnosing network issues. - Process and Performance Tools
-
ps: Lists currently running processes within containers.top: Provides real-time insights into resource usage by processes within containers.htop: Interactive process viewer for monitoring resource utilization.perf: CPU performance profiling, tracing, and monitoring, aiding in pinpointing performance bottlenecks within the system or applications.vmstat: Reports virtual memory statistics within containers, aiding in performance analysis.iostat: Monitors input/output statistics for block devices within containers.gdb(GNU Debugger): A command-line debugger that helps in examining and debugging programs by allowing users to track and control their execution, inspect variables, and analyze memory and registers during runtime. For more information, see the Debugging applications within Red Hat OpenShift containers article.strace: Intercepts and records system calls made by a program, aiding in troubleshooting by revealing interactions between the program and the operating system. - Security and Access Control Tools
-
sudo: Lets you run commands with elevated privileges.chroot: Changes the root directory for a command, helpful in testing or troubleshooting within a different root directory. - Podman-Specific Tools
-
podman logs: Batch-retrieves whatever logs are present for one or more containers at the time of execution.podman inspect: Displays the low-level information on containers and images as identified by name or ID.podman events: Monitor and print events that occur in Podman. Each event includes a timestamp, a type, a status, a name (if applicable), and an image (if applicable). The default logging mechanism isjournald.podman run --health-cmd: Use the health check to determine the health or readiness of the process running inside the container.podman top: Display the running processes of the container.podman exec: Running commands in or attaching to a running container is extremely useful to get a better understanding of what is happening in the container.podman export: When the container fails, it is difficult to know the reasons. Exporting the filesystem structure from the container will allow for checking other logs files that might not be in the mounted volumes.