AZ-204 Develop Azure compute solutions Practice Question
Network Topology
You run the command above to create an Azure Container Instance. The container exits with a non-zero exit code. You need to check the logs to debug the issue. Which command should you use next?
⚠ Common exam trap
A common mix-up: candidates confuse `az container attach` (for live streaming of a running container) with `az container logs` (for retrieving historical logs from a stopped container), leading them to choose option A even though the container has already exited.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
az container logs --resource-group myRG --name mycontainer
The correct command is `az container logs` because it retrieves the stdout and stderr logs from a container that has exited, which is essential for debugging exit code failures. Since the container has already exited with a non-zero exit code, you need to inspect its logged output to understand the cause of the failure, and this command directly fetches those logs without requiring an active container.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
az container attach --resource-group myRG --name mycontainer
Why it's wrong here
The az container attach command is designed to stream the standard output and standard error from a *currently running* Azure Container Instance. It establishes a real-time connection to the container's active console, allowing users to observe live log events as they occur. If the container has already exited, there are no active streams to attach to, making this command unsuitable for retrieving historical logs from a stopped or completed container instance.
- ✓
az container logs --resource-group myRG --name mycontainer
Why this is correct
The az container logs command is the correct utility for retrieving the complete historical standard output and standard error logs generated by an Azure Container Instance. Azure persists these logs even after the container has exited, enabling crucial post-mortem analysis and debugging of application failures. This command effectively fetches the accumulated log data, providing comprehensive insight into the container's execution lifecycle and any termination events.
- ✗
az container exec --resource-group myRG --name mycontainer --exec-command /bin/sh
Why it's wrong here
The az container exec command facilitates executing a specific command or launching an interactive shell *within* a *running* Azure Container Instance. This functionality is invaluable for real-time troubleshooting, inspecting the container's file system, or running diagnostic tools while the application is active. However, because it requires an active container process to execute commands against, it cannot be used to interact with or extract information from a container that has already terminated.
- ✗
az container show --resource-group myRG --name mycontainer --query containers[0].instanceView.currentState.exitCode
Why it's wrong here
The az container show command provides detailed metadata and status information about an Azure Container Instance, including its configuration, state, and events. While it can be used with a --query parameter to extract specific attributes like the exitCode from the container's instanceView, it does not retrieve the actual standard output or standard error logs. This command is useful for checking the container's overall health and termination status, but it does not provide the granular application output necessary for comprehensive debugging.
Go deeper
Related to this question
About these practice questions
Courseiva writes every AZ-204 question from scratch — 881 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This AZ-204 practice question is part of Courseiva's free Microsoft certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the AZ-204 exam.