Member-only story
Docker interview questions!
📌 How would you troubleshoot a Docker container that is stuck in an “Exited” state immediately after starting?
âś… First, check the logs of the container using docker logs <container_id>. The logs often provide clues about what went wrong.
âś… Check the exit code of the container using docker inspect <container_id> or docker ps -a.
âś… An exit code of 137 typically means the container was killed due to memory limits.
âś… Exit code 1 often means an application error, while 143 is typically a result of the container receiving a SIGTERM.
âś… If there are no obvious application errors, inspect the Dockerfile for issues with the ENTRYPOINT or CMD instructions. If these are incorrectly set or missing, the container will exit immediately.
âś… Verify if the host has enough system resources, such as CPU, memory, or disk space. You can check this with docker stats or docker system df.
đź“Ś You observe that a container is consuming an excessive amount of memory. How do you troubleshoot this?
âś… Use the docker stats command to check the live memory usage of containers.
âś… If the memory consumption is high, you might consider:
✅ Adding memory limits using – memory or – memory-swap flags when starting the container to restrict its memory usage.
✅ Check if there are memory leaks in the application by reviewing the application logs or…