docker-cli

leobrival's avatarfrom leobrival

Docker CLI expert for containerization. Use when users need to build, run, manage containers, images, networks, volumes, or compose applications.

0stars🔀0forks📁View on GitHub🕐Updated Jan 10, 2026

When & Why to Use This Skill

This Claude skill acts as a specialized Docker CLI expert designed to streamline containerization workflows. It helps users navigate the complexities of building optimized images, managing container lifecycles, orchestrating multi-service environments with Docker Compose, and implementing robust data persistence and networking strategies. By providing instant access to best practices and troubleshooting steps, it significantly reduces the friction of managing cloud-native infrastructure.

Use Cases

  • Automating the build-tag-push workflow to ensure consistent image deployment across different environments and registries.
  • Setting up efficient local development environments using volume mounts for real-time code synchronization and hot-reloading.
  • Orchestrating complex multi-container applications with Docker Compose, including service scaling and inter-container communication.
  • Diagnosing and resolving critical container issues such as unexpected exits, network connectivity failures, and volume permission errors.
  • Optimizing resource management by implementing CPU/memory limits and performing system-wide cleanup of unused Docker resources.
namedocker-cli
descriptionDocker CLI expert for containerization. Use when users need to build, run, manage containers, images, networks, volumes, or compose applications.

Docker CLI Guide

Docker is a containerization platform that packages applications and dependencies into isolated containers. This guide provides essential workflows and quick references for common Docker operations.

Quick Start

# Check Docker installation
docker --version

# Run your first container
docker run hello-world

# Run interactive container
docker run -it ubuntu bash

# Run container in background
docker run -d nginx

# List running containers
docker ps

# Stop a container
docker stop container_name

Common Workflows

Workflow 1: Build and Run an Application

# Create Dockerfile in your project directory
# Build image
docker build -t myapp:latest .

# Run container with port mapping
docker run -d -p 8080:80 --name myapp myapp:latest

# View logs
docker logs -f myapp

# Access container shell
docker exec -it myapp bash

Workflow 2: Development with Hot Reload

# Run with volume mount for live code updates
docker run -d \
  -p 8080:80 \
  -v $(pwd)/src:/app/src \
  --name myapp-dev \
  myapp:dev

# Watch logs in real-time
docker logs -f myapp-dev

# Restart after configuration changes
docker restart myapp-dev

Workflow 3: Multi-Container Application with Docker Compose

# Create docker-compose.yml with services
# Start all services
docker compose up -d

# View service logs
docker compose logs -f

# Scale a service
docker compose up -d --scale api=3

# Stop all services
docker compose down

# Stop and remove volumes
docker compose down -v

Workflow 4: Push Image to Registry

# Login to registry
docker login

# Build and tag image
docker build -t myapp:latest .
docker tag myapp:latest username/myapp:v1.0.0
docker tag myapp:latest username/myapp:latest

# Push to registry
docker push username/myapp:v1.0.0
docker push username/myapp:latest

Workflow 5: Debug Container Issues

# Check container status
docker ps -a

# View container logs
docker logs container_name

# Inspect container details
docker inspect container_name

# Run interactive shell for debugging
docker run -it --entrypoint /bin/bash myapp:latest

# Check container resource usage
docker stats container_name

Decision Tree

When to use which command:

  • To run a new container: Use docker run with appropriate flags
  • To execute commands in running container: Use docker exec -it container_name bash
  • To build an image: Use docker build -t name:tag .
  • To manage multiple services: Use docker compose up/down
  • To check container status: Use docker ps or docker ps -a
  • To view logs: Use docker logs -f container_name
  • To clean up resources: Use docker system prune or specific prune commands
  • For detailed command syntax: See Commands Reference
  • For complex scenarios: See Common Patterns
  • For troubleshooting: See Troubleshooting Guide

Common Patterns

Running Containers with Options

# With environment variables
docker run -e ENV_VAR=value -e API_KEY=secret myapp

# With resource limits
docker run --memory=512m --cpus=1.5 myapp

# With restart policy
docker run --restart=unless-stopped myapp

# With custom network
docker run --network mynetwork myapp

# With volume mount
docker run -v mydata:/app/data myapp

Container-to-Container Communication

# Create custom network
docker network create myapp-network

# Run containers on same network
docker run -d --name database --network myapp-network postgres:15
docker run -d --name app --network myapp-network -p 8080:80 myapp

# Containers can now access each other by name
# Example: app can connect to database using hostname "database"

Data Persistence

# Create named volume
docker volume create myapp-data

# Use volume in container
docker run -d -v myapp-data:/var/lib/postgresql/data postgres:15

# Backup volume data
docker run --rm \
  -v myapp-data:/data \
  -v $(pwd):/backup \
  ubuntu tar czf /backup/backup.tar.gz /data

Troubleshooting

Common Issues:

  1. Container exits immediately

  2. Can't access service on published port

  3. Permission denied errors

  4. Disk space issues

  5. Network connectivity issues

    • Quick fix: Check container network with docker network inspect bridge
    • See: Network Issues

For detailed troubleshooting steps, see the Troubleshooting Guide.

Reference Files

Load as needed for detailed information:

  • Commands Reference - Complete CLI command documentation with all flags and options. Use when you need exact syntax or flag details for any Docker command.

  • Common Patterns - Real-world patterns and workflows for development, multi-stage builds, networking, volumes, CI/CD, security, and production deployments. Use for implementing specific workflows or integrations.

  • Troubleshooting Guide - Detailed error messages, diagnosis steps, and resolution strategies for container, image, network, volume, performance, and system issues. Use when encountering errors or unexpected behavior.

When to use each reference:

  • Use Commands Reference when you need exact syntax, flag combinations, or comprehensive command documentation
  • Use Common Patterns for implementing multi-container setups, production configurations, or CI/CD pipelines
  • Use Troubleshooting when containers won't start, services are unreachable, or you encounter permission/network/performance issues

Resources