DevOps Interview Preparation Course

Docker

Docker Question 2

In this article, we explore a frequently asked Docker interview question in the DevOps space:

"What happens to container logs when you restart a container? Are the logs lost, or do they persist?"

This question tests your practical Docker knowledge. If you’re new to Docker, you may not have encountered this scenario before, making the answer a bit challenging. Here, we clarify the concept and guide you on how to respond confidently during interviews.

When you restart a Docker container, the logs generated by your application are not lost. Typically, these logs are stored in locations such as /var/log or other directories defined by your application's configuration. Whether you stop and then start the container or simply restart it, the logs remain intact. Note, however, that the application might begin writing to a new log file upon restart.

The image contains text explaining that containers are stateless, leading to log loss if deleted, but not if they are stopped, started, or restarted.

Note

Although container logs persist across restarts, if a container is deleted, its logs are also removed. To avoid losing log data, it is recommended to use external persistent storage or integrate centralized logging solutions such as Splunk or CloudTrail.

The image contains text explaining that containers are stateless, leading to log loss if deleted, but logs are retained if containers are stopped, started, or restarted.

Key Takeaways for Docker Interviews

  • Logs Persistence: When you start, stop, or restart a container, the logs persist.
  • Log Rotation Consideration: Depending on your application's log rotation strategy, executing the docker logs command might display output from a new log file if logging restarts.
  • Container Deletion: Deleting a container will also delete any logs stored inside it.
  • Best Practices: Use external log storage solutions to safeguard logs when a container is deleted.

This guide should equip you with the insight needed to effectively answer questions about Docker container logs during your DevOps interviews. Good luck with your interview preparation and future endeavors in container management!

Watch Video

Watch video content

Previous
Docker Question 1