At this point, you’ve deployed your containers and they’re running (or almost). But how can you tell what’s going on inside them?Docker provides several tools for monitoring and diagnosing your containers.
1. View logs with docker logs
Each container keeps a log of its processes’ events and output.
- Basic command:
docker logs nom_du_conteneur
- To monitor logs in real time (such as
tail -f):
docker logs -f nom_du_conteneur
Practical example:
If your Apache container is named mon-apache, you can view errors and requests live:
docker logs -f mon-apache
2. Inspect a container with docker inspect
Sometimes you need detailed technical information about a container: IP, volumes, environment variables…
docker inspect nom_du_conteneur
- Beginner tip: You can combine this with
grepto filter what interests you:
docker inspect mon-apache | grep IPAddress
3. Interact directly with the container: docker exec -it
This is probably the most convenient tool for entering a container, just like a virtual machine.
- Syntax:
docker exec -it nom_du_conteneur bash
- If the container doesn’t have bash (like some lightweight containers), use sh:
docker exec -it nom_du_conteneur sh
Practical example:
You want to check the Apache configuration or access your site’s files:
docker exec -it mon-apache bash
cd /var/www/html
ls -l
Thenexit to exit.
4. Quick recap for beginners
docker logs -f→ View logs in real time.docker inspect→ Understand the internal configuration.docker exec -it→ Enter the container to explore or troubleshoot.
Note: With these three commands, you can diagnose almost anything without needing to delete or redeploy your containers.