Skip to content

emy3/docker-logs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Docker Logs 🐳

A Python utility that aggregates and displays logs from all running Docker containers in a single, color-coded terminal view.

✨ Features

  • Multi-container log streaming: View logs from all running containers simultaneously
  • Color-coded output: Each container gets a unique color for easy identification
  • Real-time updates: Streams logs as they happen using Docker's log streaming API
  • Multi-threaded: Efficiently handles multiple containers using Python threading
  • Keyboard interrupt support: Clean exit with Ctrl+C

📋 Requirements

  • Python 3.6 or higher
  • Docker Engine running and accessible
  • Docker daemon socket access (typically requires running with appropriate permissions)

🔧 Installation

  1. Clone this repository:
git clone https://github.com/emy3/docker-logs.git
cd docker-logs
  1. Install the required Python dependencies:
pip install docker rich

Alternatively, you can create a virtual environment:

python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install docker rich

🚀 Usage

Simply run the script:

python dockerLog.py

The script will:

  1. Connect to your local Docker daemon
  2. List all currently running containers
  3. Start streaming logs from each container
  4. Display logs with color-coded container names

To stop the log stream, press Ctrl+C.

📝 Example Output

webapp: 127.0.0.1 - - [11/Oct/2025 13:30:45] "GET / HTTP/1.1" 200 -
database: 2025-10-11 13:30:46.123 UTC [1] LOG:  database system is ready to accept connections
redis: 1:M 11 Oct 2025 13:30:47.456 * Ready to accept connections
webapp: 127.0.0.1 - - [11/Oct/2025 13:30:48] "GET /api/users HTTP/1.1" 200 -

Each container name is displayed in a unique color, making it easy to follow specific container logs in a busy environment.

🛠️ How It Works

  1. Docker Connection: Uses the Docker Python SDK to connect to the Docker daemon via environment variables
  2. Container Discovery: Lists all currently running containers
  3. Color Assignment: Assigns a random hex color to each container for visual distinction
  4. Threaded Streaming: Creates a separate thread for each container to stream logs independently
  5. Rich Console Output: Uses the rich library for colored terminal output

⚠️ Troubleshooting

Permission Denied Error

If you encounter permission errors when connecting to Docker, ensure:

  • Your user is in the docker group: sudo usermod -aG docker $USER
  • Docker daemon is running: sudo systemctl status docker
  • Log out and back in for group changes to take effect

No Containers Found

The script only shows logs from currently running containers. Start some containers first:

docker run -d nginx
docker run -d redis

Module Not Found

Install the required dependencies:

pip install docker rich

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🤝 Contributing

Contributions are welcome! Feel free to:

  • Report bugs
  • Suggest new features
  • Submit pull requests

👤 Author

Created by honeydu

🙏 Acknowledgments

About

python script to tail and show all docker container logs in one

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages