# Lazydocker Terminal UI

> Terminal-based Docker management with ncurses interface.

- Category: DevOps & CI/CD
- Difficulty: beginner
- Components: lazydocker, redis, postgres
- Tags: lazydocker, docker, terminal, tui, cli
- Source: https://docker.recipes/devops/lazydocker-cli

## Overview

Lazydocker is a terminal-based user interface built by Jesse Duffield that transforms Docker container management from complex CLI commands into an intuitive, ncurses-driven experience. This TUI application provides real-time monitoring, log viewing, and container interaction through a keyboard-driven interface that displays container stats, images, volumes, and networks in organized panels. Unlike traditional Docker management tools that require memorizing numerous commands or switching between web interfaces, lazydocker consolidates everything into a single, responsive terminal application.

This stack combines lazydocker with Redis 7 and PostgreSQL 15 to create a practical demonstration environment where you can experience managing real database services through the terminal interface. The Redis instance provides fast in-memory caching capabilities while PostgreSQL delivers robust relational database functionality, giving you two distinctly different service types to monitor, restart, and troubleshoot using lazydocker's streamlined interface. This combination showcases how lazydocker handles both lightweight Alpine-based containers and more complex database services with different resource requirements and startup behaviors.

Developers working with multi-container applications, system administrators managing development environments, and DevOps engineers who prefer terminal-based workflows will find this stack particularly valuable. The setup eliminates the need to constantly run 'docker ps', 'docker logs', and 'docker exec' commands by providing visual container health monitoring, one-key log access, and instant shell access to running containers. This makes it ideal for debugging application issues, monitoring resource usage during development, and teaching Docker concepts through a more accessible interface than raw CLI commands.

## Features

- Real-time container CPU, memory, and network I/O statistics display with visual graphs
- Split-pane log viewing with automatic scrolling and search functionality across multiple containers
- One-key container actions: restart, stop, remove, and shell access without typing docker commands
- Docker socket mounting enables full Docker daemon access for complete container lifecycle management
- Persistent lazydocker configuration storage for custom keybindings and display preferences
- Multi-service monitoring dashboard showing Redis connection stats and PostgreSQL process information
- Keyboard-driven navigation with vim-like controls for rapid container switching and management
- Container inspection views displaying environment variables, port mappings, and volume mounts

## Use cases

- Local development environment monitoring where developers need to quickly check database connection status and application logs
- Database administration tasks requiring frequent PostgreSQL container restarts and Redis cache clearing during development cycles
- Docker learning environments where students can visually understand container relationships without memorizing CLI syntax
- Troubleshooting microservice applications by simultaneously monitoring Redis cache hit rates and PostgreSQL query performance
- Development team demonstrations showing container health status and real-time log output during application testing
- CI/CD pipeline debugging where engineers need to quickly inspect container states and logs after deployment failures
- Homelab container management for users running personal Redis and PostgreSQL instances who prefer terminal interfaces over web UIs

## Prerequisites

- Docker Engine with Unix socket access at /var/run/docker.sock for lazydocker container communication
- Minimum 1GB RAM available for PostgreSQL container plus 256MB for Redis and lazydocker operations
- Terminal with ncurses support and minimum 80x24 character display for proper lazydocker interface rendering
- Basic familiarity with keyboard navigation and vim-style controls for efficient lazydocker usage
- Available ports 6379 for Redis external access if connecting applications outside the Docker network
- Docker Compose v2.0+ for proper service dependency handling and volume management

## docker-compose.yml

```yaml
services:
  lazydocker:
    image: lazyteam/lazydocker:latest
    stdin_open: true
    tty: true
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - lazydocker_config:/root/.config/lazydocker
    network_mode: bridge

  # Sample services to manage
  redis:
    image: redis:7-alpine
    ports:
      - "6379:6379"

  postgres:
    image: postgres:15-alpine
    environment:
      - POSTGRES_PASSWORD=example

volumes:
  lazydocker_config:
```

## .env

```bash
# Lazydocker
# Run: docker compose run lazydocker
# Terminal UI for Docker management
```

## Usage notes

- Run: docker compose run lazydocker
- Terminal-based UI
- Navigate with arrow keys
- View logs, stats, exec into containers
- Keyboard shortcuts for common actions

## Troubleshooting

- Permission denied accessing Docker socket: Add your user to the docker group with 'sudo usermod -aG docker $USER' and restart your session
- Lazydocker interface appears garbled or truncated: Increase terminal size to at least 100x30 characters and ensure TERM environment variable is properly set
- PostgreSQL container fails to start with 'database system was interrupted': Remove the postgres data volume with 'docker volume rm' and recreate the container
- Redis connection refused errors in logs: Check that port 6379 isn't already in use by another Redis instance with 'netstat -tlnp | grep 6379'
- Lazydocker shows no containers or services: Verify Docker daemon is running and socket permissions allow access with 'docker ps' command outside lazydocker
- Container stats showing zero or incorrect values: Restart the Docker daemon and recreate lazydocker container to refresh metric collection

