Introduction
Welcome to the magical village of Fairy Tale Land! In this whimsical setting, you will take on the role of a magical farmer who tends to enchanted creatures and plants. Your goal is to learn how to view logs from Docker containers to maintain the magical ecosystem of the village.
Setup Docker Logging
In this step, you will set up logging for a Docker container and explore the logs.
Pull the official
nginxDocker image:docker pull nginxCreate a Docker container named
magical-nginxusing thenginximage:docker run -d -p 80:80 --name magical-nginx nginxView the logs of the
magical-nginxcontainer:docker logs magical-nginx
Streaming Container Logs
In this step, you will learn how to stream the logs from a running container in real time.
Stream the logs from the
magical-nginxcontainer:docker logs -f magical-nginxWhile keeping the log stream open, add a web service mapping, if service mapping is successful, the environment will automate access to the default Nginx web page in a separate tab to generate log entries.
curl http://localhostObserve the real-time log entries appearing in the log stream.
Clearing Container Logs
In this step, you will explore how to clear the logs of a Docker container.
Clear the logs of the
magical-nginxcontainer:sudo sh -c 'echo "" > $(docker inspect --format="{{.LogPath}}" magical-nginx)'Confirm that the logs have been cleared by attempting to view the logs again:
docker logs magical-nginx
Summary
In this lab, you learned the essential skills of viewing Docker container logs in a magical farming environment. By setting up logging, streaming real-time logs, and clearing logs, you have gained a deeper understanding of how to monitor and maintain your magical Docker containers. This knowledge will empower you to keep the fantastical creatures and plants of Fairy Tale Land thriving in harmony. Happy logging, magical farmer!



