Skip to main content
hooksSource-backedReview first Safety Privacy
Docker logo

Docker Container Auto Rebuild - Hooks

A PostToolUse hook that watches for edits to Docker-related files (Dockerfile, docker-compose, .dockerfile, .dockerignore).

by JSONbored·added 2025-09-19·
HarnessClaude Code
Trigger:PostToolUse
Review first review before installing

Open the source and read safety notes before installing.

Citation facts

Source-backed facts for citing this resource, derived directly from the registry — also available as plain text for AI assistants.

Source URLs
https://docs.docker.com/reference/cli/docker/compose/, https://github.com/JSONbored/awesome-claude/blob/main/content/hooks/docker-container-auto-rebuild.mdx
Brand
Docker
Brand domain
docker.com
Brand asset source
brandfetch
Safety notes
Runs automatically after write or edit activity on Dockerfile, docker-compose, dockerfile, and dockerignore paths., Invokes docker build or docker compose build and can consume CPU, disk, network, and local Docker daemon resources., Uses the Dockerfile directory or compose-file directory as the build context, so incorrect paths can include more files than expected.
Privacy notes
Reads Docker-related files and may send build context files to the local Docker daemon during image builds., Build logs may reveal image names, service names, dependency URLs, and package-install output., Prints the first lines of .dockerignore files to local hook output when those files are edited.
Author
JSONbored
Claim status
unclaimed
Last verified
2025-09-19

Decision playbook

Review trust signals before you adopt

Signals are present but mixed. Use the checklist below to confirm the source and operational safety for your environment.

Compare context
Selected

0

Current score

78

Baseline

Delta

No baseline selected

No major trust-signal divergence detected in the current selection.

Source and provenance checks

Complete

Confirm ownership and provenance before trusting install instructions.

  • Source link availableRequired

    Open the canonical repository and verify ownership.

    Done
  • Source provenance statusRequired

    Marked as source-backed.

    Done
  • Metadata reviewed

    Registry metadata indicates a reviewed listing.

    Done

Safety and privacy checks

Complete

Validate risk disclosures before installation or API wiring.

  • Safety notes presentRequired

    Review the listed safety guidance before running commands.

    Done
  • Privacy notes presentRequired

    Review data handling notes before connecting accounts or secrets.

    Done
  • Trust level risk gateRequired

    Trust level does not block evaluation.

    Done

Package and install checks

Needs review

Check package metadata and artifact integrity signals.

  • Install payload available

    Install or copy payload is available for review.

    Done
  • Package verification flag

    No package verification flag provided.

    Pending
  • Checksum metadata

    No checksum provided for downloaded artifact.

    Pending

Compare-driven decision checks

Needs review

Use compare context to validate trade-offs before adoption.

  • Compare tray has multiple entries

    Add at least one more entry to compare trust differences.

    Pending
  • Baseline comparison available

    No baseline peer selected yet.

    Pending
  • Diverging trust signals identified

    No major trust-signal divergence found.

    Pending

Setup at a glance

CLI install

Copy-ready — paste the snippet to get started.

Install command

Provided

Config snippet

Provided

Copy snippet

Provided

Prerequisites

None

Platforms

1 listed

Difficulty

0/100

Adoption plan

Balanced adoption plan

Current risk score 16/100. Use staged verification before broader rollout.

Risk 16

Pre-adoption checks

Validate source and review signals before any execution.

  • Confirm source provenanceRequired

    Source URL/provenance metadata is present.

    Done
  • Confirm metadata review state

    Listing has review metadata.

    Done
  • Verify install payload

    Install/config payload exists and can be inspected.

    Done

Security checks

Confirm safety, privacy, and package integrity signals.

  • Review safety notesRequired

    Safety notes are present.

    Done
  • Review privacy notesRequired

    Privacy notes are present.

    Done
  • Verify package integrity metadata

    No package verification/checksum metadata.

    Pending

Rollout

Adopt in controlled steps based on the selected plan.

  • Run in isolated sandbox firstRequired

    Use a constrained sandbox and observe behavior across multiple tasks.

    Pending
  • Roll out graduallyRequired

    Roll out to a small cohort before wider usage.

    Pending
  • Set monitoring and fallback

    Define rollback path and monitor errors after adoption.

    Pending

Evidence readiness

Evidence readiness matrix · balanced

Required evidence gates are covered (5/6 signals complete).

Risk 15

Source provenance

Present

Source repository/provenance is listed.

Required in this preset

Metadata review

Present

Review metadata is present.

Required in this preset

Safety notes

Present

Safety notes are present.

Required in this preset

Privacy notes

Present

Privacy notes are present.

Optional in this preset

Package integrity

Missing

Package integrity metadata is missing.

Optional in this preset

Install payload

Present

Install payload is available.

Required in this preset

Required evidence gates are covered for this preset.

Decision timeline

Decision timeline · balanced

5/6 steps complete with no blocking gaps for this preset.

Risk 14

triage

Confirm source provenanceRequired

Source/provenance metadata is available.

Done

triage

Check metadata review statusRequired

Review metadata is available.

Done

verify

Review safety notesRequired

Safety notes are available.

Done

verify

Review privacy notes

Privacy notes are available.

Done

verify

Validate package integrity metadata

Package integrity metadata is missing.

Pending

rollout

Verify install payload and commandsRequired

Install payload is available.

Done

No required blockers for this timeline preset.

Safety & privacy surface

Safety & privacy surface

3 safety and 3 privacy notes across 3 risk areas. Review closely: network access.

3 areas
  • SafetyLocal filesRuns automatically after write or edit activity on Dockerfile, docker-compose, dockerfile, and dockerignore paths.
  • SafetyNetwork accessInvokes docker build or docker compose build and can consume CPU, disk, network, and local Docker daemon resources.
  • SafetyLocal filesUses the Dockerfile directory or compose-file directory as the build context, so incorrect paths can include more files than expected.
  • PrivacyLocal filesReads Docker-related files and may send build context files to the local Docker daemon during image builds.
  • PrivacyExecution & processesBuild logs may reveal image names, service names, dependency URLs, and package-install output.
  • PrivacyLocal filesPrints the first lines of .dockerignore files to local hook output when those files are edited.

Safety notes

  • Runs automatically after write or edit activity on Dockerfile, docker-compose, dockerfile, and dockerignore paths.
  • Invokes docker build or docker compose build and can consume CPU, disk, network, and local Docker daemon resources.
  • Uses the Dockerfile directory or compose-file directory as the build context, so incorrect paths can include more files than expected.

Privacy notes

  • Reads Docker-related files and may send build context files to the local Docker daemon during image builds.
  • Build logs may reveal image names, service names, dependency URLs, and package-install output.
  • Prints the first lines of .dockerignore files to local hook output when those files are edited.

Schema details

Install type
cli
Reading time
1 min
Difficulty score
0
Troubleshooting
Yes
Breaking changes
No
Skill and platform metadata
Retrieval sources
https://docs.docker.com/reference/cli/docker/compose/https://code.claude.com/docs/en/hooks
Runtime and command metadata
Trigger
PostToolUse
Script language
bash
Script body
#!/usr/bin/env bash

# Read the tool input from stdin
INPUT=$(cat)
TOOL_NAME=$(echo "$INPUT" | jq -r '.tool_name')
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // .tool_input.path // ""')

if [ -z "$FILE_PATH" ]; then
  exit 0
fi

# Check if it's a Docker-related file
if [[ "$FILE_PATH" == *Dockerfile* ]] || [[ "$FILE_PATH" == *docker-compose* ]] || [[ "$FILE_PATH" == *.dockerfile ]] || [[ "$FILE_PATH" == *dockerignore* ]]; then
  echo "🐳 Docker file detected: $FILE_PATH" >&2
  
  # Check if Docker is available
  if ! command -v docker &> /dev/null; then
    echo "⚠️ Docker not found - install Docker to enable auto-rebuild" >&2
    exit 0
  fi
  
  # Check if Docker daemon is running
  if ! docker info &> /dev/null; then
    echo "⚠️ Docker daemon not running - start Docker to enable auto-rebuild" >&2
    exit 0
  fi
  
  # Handle different Docker file types
  if [[ "$FILE_PATH" == *Dockerfile* ]] || [[ "$FILE_PATH" == *.dockerfile ]]; then
    echo "🔨 Dockerfile modified - rebuilding Docker image..." >&2
    
    # Determine image name (use directory name by default)
    IMAGE_NAME=$(basename "$(pwd)"):latest
    
    # Check if there's a specific Dockerfile path
    DOCKERFILE_DIR=$(dirname "$FILE_PATH")
    
    echo "📦 Building image: $IMAGE_NAME" >&2
    echo "📁 Build context: $DOCKERFILE_DIR" >&2
    
    # Build the Docker image
    if docker build -t "$IMAGE_NAME" "$DOCKERFILE_DIR" 2>&1; then
      echo "✅ Docker image '$IMAGE_NAME' rebuilt successfully" >&2
      
      # Show image details
      IMAGE_ID=$(docker images -q "$IMAGE_NAME" | head -1)
      if [ -n "$IMAGE_ID" ]; then
        IMAGE_SIZE=$(docker images "$IMAGE_NAME" --format "table {{.Size}}" | tail -1)
        echo "📊 Image ID: $IMAGE_ID, Size: $IMAGE_SIZE" >&2
      fi
    else
      echo "❌ Docker image build failed" >&2
      exit 1
    fi
    
  elif [[ "$FILE_PATH" == *docker-compose* ]]; then
    echo "🔨 Docker Compose file modified - rebuilding services..." >&2
    
    COMPOSE_FILE=$(basename "$FILE_PATH")
    COMPOSE_DIR=$(dirname "$FILE_PATH")
    
    echo "📁 Compose file: $COMPOSE_FILE" >&2
    echo "📁 Working directory: $COMPOSE_DIR" >&2
    
    # Change to the directory containing the compose file
    cd "$COMPOSE_DIR" || exit 1
    
    # Check if docker-compose or docker compose is available
    if command -v docker-compose &> /dev/null; then
      COMPOSE_CMD="docker-compose"
    elif docker compose version &> /dev/null; then
      COMPOSE_CMD="docker compose"
    else
      echo "⚠️ Neither docker-compose nor 'docker compose' found" >&2
      exit 0
    fi
    
    # Build the services
    echo "🔧 Using: $COMPOSE_CMD" >&2
    if $COMPOSE_CMD -f "$COMPOSE_FILE" build 2>&1; then
      echo "✅ Docker Compose services rebuilt successfully" >&2
      
      # Show service status
      echo "📊 Service status:" >&2
      $COMPOSE_CMD -f "$COMPOSE_FILE" ps --format "table {{.Service}}\t{{.Status}}" 2>/dev/null || true
    else
      echo "❌ Docker Compose build failed" >&2
      exit 1
    fi
    
  elif [[ "$FILE_PATH" == *dockerignore* ]]; then
    echo "📝 .dockerignore file modified" >&2
    echo "💡 This will affect the next Docker build by excluding specified files" >&2
    
    # Show dockerignore contents for reference
    if [ -f "$FILE_PATH" ]; then
      echo "📋 Current .dockerignore rules:" >&2
      head -10 "$FILE_PATH" >&2
    fi
  fi
  
  # General Docker tips
  echo "" >&2
  echo "💡 Docker Development Tips:" >&2
  echo "   • Use .dockerignore to exclude unnecessary files" >&2
  echo "   • Consider multi-stage builds for smaller images" >&2
  echo "   • Use docker system prune to clean up unused resources" >&2
  
else
  echo "File $FILE_PATH is not a Docker-related file, skipping rebuild" >&2
fi

exit 0
Full copyable content
{
  "hooks": {
    "postToolUse": {
      "script": "./.claude/hooks/docker-container-auto-rebuild.sh",
      "matchers": [
        "write",
        "edit"
      ]
    }
  }
}

About this resource

Features

  • Automatic Docker image rebuilding on Dockerfile changes, deriving the image tag from the current directory name and using the Dockerfile's directory as the build context
  • Docker Compose service rebuilding for compose file updates with service status reporting and support for both the docker-compose and docker compose commands
  • Intelligent file detection for Docker-related configurations (Dockerfile, docker-compose.yml, .dockerignore, .dockerfile) with pattern matching and file extension detection
  • Support for multiple Docker file name patterns and variations via shell glob matching on the edited file path
  • Build status reporting and error handling with image ID and size information for Dockerfile builds and service status display for Docker Compose
  • Development environment synchronization with automatic container updates ensuring running containers reflect latest code changes
  • Graceful skipping when the Docker CLI is missing or the Docker daemon is not running, so edits without Docker available do not fail
  • .dockerignore detection that prints the first lines of the edited file as a reminder of which paths are excluded from the build context

Use Cases

  • Automated Docker development workflow synchronization providing real-time container rebuilding when Dockerfiles are modified during active development
  • Real-time container rebuilding during development ensuring development containers always reflect the latest Dockerfile changes without manual rebuild commands
  • DevOps pipeline integration for container updates enabling automated container rebuilding in CI/CD pipelines when Docker configurations change
  • Multi-service application development with Docker Compose automatically rebuilding affected services when compose files or Dockerfiles are modified
  • Continuous integration for containerized applications ensuring containers are rebuilt and tested automatically when Docker configurations change
  • Development workflow optimization providing immediate feedback on Docker build success or failure during active development

Installation

  1. Create hooks directory: mkdir -p .claude/hooks
  2. Create hook file: touch .claude/hooks/docker-container-auto-rebuild.sh
  3. Make executable: chmod +x .claude/hooks/docker-container-auto-rebuild.sh
  4. Add configuration from Hook Configuration section above to .claude/settings.json or ~/.claude/settings.json
  5. Alternative: Use the interactive /hooks command in Claude Code

Config paths

  • Local (not committed): .claude/settings.local.json
  • User settings (global): ~/.claude/settings.json
  • Project-wide (committed): .claude/settings.json

Requirements

  • Claude Code CLI installed
  • Project directory initialized
  • Bash shell available
  • Docker Engine installed and running
  • Docker Compose v2 (docker compose) or docker-compose command available
  • Docker daemon accessible (user in docker group on Linux)

Hook Configuration

{
  "hooks": {
    "postToolUse": {
      "script": "./.claude/hooks/docker-container-auto-rebuild.sh",
      "matchers": ["write", "edit"]
    }
  }
}

Hook Script

#!/usr/bin/env bash

# Read the tool input from stdin
INPUT=$(cat)
TOOL_NAME=$(echo "$INPUT" | jq -r '.tool_name')
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // .tool_input.path // ""')

if [ -z "$FILE_PATH" ]; then
  exit 0
fi

# Check if it's a Docker-related file
if [[ "$FILE_PATH" == *Dockerfile* ]] || [[ "$FILE_PATH" == *docker-compose* ]] || [[ "$FILE_PATH" == *.dockerfile ]] || [[ "$FILE_PATH" == *dockerignore* ]]; then
  echo "🐳 Docker file detected: $FILE_PATH" >&2

  # Check if Docker is available
  if ! command -v docker &> /dev/null; then
    echo "⚠️ Docker not found - install Docker to enable auto-rebuild" >&2
    exit 0
  fi

  # Check if Docker daemon is running
  if ! docker info &> /dev/null; then
    echo "⚠️ Docker daemon not running - start Docker to enable auto-rebuild" >&2
    exit 0
  fi

  # Handle different Docker file types
  if [[ "$FILE_PATH" == *Dockerfile* ]] || [[ "$FILE_PATH" == *.dockerfile ]]; then
    echo "🔨 Dockerfile modified - rebuilding Docker image..." >&2

    # Determine image name (use directory name by default)
    IMAGE_NAME=$(basename "$(pwd)"):latest

    # Check if there's a specific Dockerfile path
    DOCKERFILE_DIR=$(dirname "$FILE_PATH")

    echo "📦 Building image: $IMAGE_NAME" >&2
    echo "📁 Build context: $DOCKERFILE_DIR" >&2

    # Build the Docker image
    if docker build -t "$IMAGE_NAME" "$DOCKERFILE_DIR" 2>&1; then
      echo "✅ Docker image '$IMAGE_NAME' rebuilt successfully" >&2

      # Show image details
      IMAGE_ID=$(docker images -q "$IMAGE_NAME" | head -1)
      if [ -n "$IMAGE_ID" ]; then
        IMAGE_SIZE=$(docker images "$IMAGE_NAME" --format "table {{.Size}}" | tail -1)
        echo "📊 Image ID: $IMAGE_ID, Size: $IMAGE_SIZE" >&2
      fi
    else
      echo "❌ Docker image build failed" >&2
      exit 1
    fi

  elif [[ "$FILE_PATH" == *docker-compose* ]]; then
    echo "🔨 Docker Compose file modified - rebuilding services..." >&2

    COMPOSE_FILE=$(basename "$FILE_PATH")
    COMPOSE_DIR=$(dirname "$FILE_PATH")

    echo "📁 Compose file: $COMPOSE_FILE" >&2
    echo "📁 Working directory: $COMPOSE_DIR" >&2

    # Change to the directory containing the compose file
    cd "$COMPOSE_DIR" || exit 1

    # Check if docker-compose or docker compose is available
    if command -v docker-compose &> /dev/null; then
      COMPOSE_CMD="docker-compose"
    elif docker compose version &> /dev/null; then
      COMPOSE_CMD="docker compose"
    else
      echo "⚠️ Neither docker-compose nor 'docker compose' found" >&2
      exit 0
    fi

    # Build the services
    echo "🔧 Using: $COMPOSE_CMD" >&2
    if $COMPOSE_CMD -f "$COMPOSE_FILE" build 2>&1; then
      echo "✅ Docker Compose services rebuilt successfully" >&2

      # Show service status
      echo "📊 Service status:" >&2
      $COMPOSE_CMD -f "$COMPOSE_FILE" ps --format "table {{.Service}}\t{{.Status}}" 2>/dev/null || true
    else
      echo "❌ Docker Compose build failed" >&2
      exit 1
    fi

  elif [[ "$FILE_PATH" == *dockerignore* ]]; then
    echo "📝 .dockerignore file modified" >&2
    echo "💡 This will affect the next Docker build by excluding specified files" >&2

    # Show dockerignore contents for reference
    if [ -f "$FILE_PATH" ]; then
      echo "📋 Current .dockerignore rules:" >&2
      head -10 "$FILE_PATH" >&2
    fi
  fi

  # General Docker tips
  echo "" >&2
  echo "💡 Docker Development Tips:" >&2
  echo "   • Use .dockerignore to exclude unnecessary files" >&2
  echo "   • Consider multi-stage builds for smaller images" >&2
  echo "   • Use docker system prune to clean up unused resources" >&2

else
  echo "File $FILE_PATH is not a Docker-related file, skipping rebuild" >&2
fi

exit 0

Examples

Docker Container Auto Rebuild Hook Script

Complete hook script that automatically rebuilds Docker containers when Dockerfiles are modified

#!/usr/bin/env bash
INPUT=$(cat)
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // .tool_input.path // ""')
if [ -z "$FILE_PATH" ]; then
  exit 0
fi
if [[ "$FILE_PATH" == *Dockerfile* ]] || [[ "$FILE_PATH" == *docker-compose* ]]; then
  echo "Docker file detected: $FILE_PATH" >&2
  if ! command -v docker &> /dev/null; then
    echo "Docker not found - install Docker to enable auto-rebuild" >&2
    exit 0
  fi
  if ! docker info &> /dev/null; then
    echo "Docker daemon not running - start Docker to enable auto-rebuild" >&2
    exit 0
  fi
  if [[ "$FILE_PATH" == *Dockerfile* ]]; then
    echo "Dockerfile modified - rebuilding Docker image..." >&2
    IMAGE_NAME=$(basename "$(pwd)"):latest
    DOCKERFILE_DIR=$(dirname "$FILE_PATH")
    export DOCKER_BUILDKIT=1
    if docker build -t "$IMAGE_NAME" -f "$FILE_PATH" "$DOCKERFILE_DIR" 2>&1; then
      echo "Docker image '$IMAGE_NAME' rebuilt successfully" >&2
    else
      echo "Docker image build failed" >&2
      exit 1
    fi
  fi
fi
exit 0

Hook Configuration

Complete hook configuration for .claude/settings.json to enable automatic Docker container rebuilding

{
  "hooks": {
    "postToolUse": {
      "script": "./.claude/hooks/docker-container-auto-rebuild.sh",
      "matchers": ["write", "edit"]
    }
  }
}

Docker Compose Auto Rebuild with BuildKit

Enhanced hook script for Docker Compose v2 with BuildKit support and --no-cache flag

#!/usr/bin/env bash
INPUT=$(cat)
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // .tool_input.path // ""')
if [[ "$FILE_PATH" == *docker-compose* ]]; then
  if command -v docker &> /dev/null && docker info &> /dev/null; then
    if docker compose version &> /dev/null; then
      COMPOSE_CMD="docker compose"
    elif command -v docker-compose &> /dev/null; then
      COMPOSE_CMD="docker-compose"
    else
      echo "Neither docker-compose nor docker compose found" >&2
      exit 0
    fi
    COMPOSE_FILE=$(basename "$FILE_PATH")
    COMPOSE_DIR=$(dirname "$FILE_PATH")
    cd "$COMPOSE_DIR" || exit 1
    echo "Rebuilding Docker Compose services..." >&2
    if $COMPOSE_CMD -f "$COMPOSE_FILE" build --no-cache 2>&1; then
      echo "Docker Compose services rebuilt successfully" >&2
    else
      echo "Docker Compose build failed" >&2
      exit 1
    fi
  fi
fi
exit 0

Docker Build with BuildKit and Progress Reporting

Enhanced hook script with BuildKit support and detailed build progress reporting

#!/usr/bin/env bash
INPUT=$(cat)
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // .tool_input.path // ""')
if [[ "$FILE_PATH" == *Dockerfile* ]]; then
  if command -v docker &> /dev/null && docker info &> /dev/null; then
    export DOCKER_BUILDKIT=1
    IMAGE_NAME=$(basename "$(pwd)"):latest
    DOCKERFILE_DIR=$(dirname "$FILE_PATH")
    DOCKERFILE_NAME=$(basename "$FILE_PATH")
    echo "Building with BuildKit: $IMAGE_NAME" >&2
    if docker build -t "$IMAGE_NAME" -f "$FILE_PATH" "$DOCKERFILE_DIR" --progress=plain 2>&1; then
      IMAGE_ID=$(docker images -q "$IMAGE_NAME" | head -1)
      IMAGE_SIZE=$(docker images "$IMAGE_NAME" --format "{{.Size}}" | head -1)
      echo "Image rebuilt: $IMAGE_ID, Size: $IMAGE_SIZE" >&2
    else
      echo "Docker build failed" >&2
      exit 1
    fi
  fi
fi
exit 0

Docker Ignore File Handler with Auto Rebuild

Enhanced hook script that triggers rebuild when .dockerignore is modified

#!/usr/bin/env bash
INPUT=$(cat)
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // .tool_input.path // ""')
if [[ "$FILE_PATH" == *.dockerignore* ]]; then
  if command -v docker &> /dev/null && docker info &> /dev/null; then
    echo ".dockerignore file modified" >&2
    echo "This will affect the next Docker build by excluding specified files" >&2
    if [ -f "$FILE_PATH" ]; then
      echo "Current .dockerignore rules:" >&2
      head -10 "$FILE_PATH" >&2
    fi
    DOCKERFILE_DIR=$(dirname "$FILE_PATH")
    DOCKERFILE="$DOCKERFILE_DIR/Dockerfile"
    if [ -f "$DOCKERFILE" ]; then
      echo "Triggering rebuild for associated Dockerfile..." >&2
      export DOCKER_BUILDKIT=1
      IMAGE_NAME=$(basename "$(pwd)"):latest
      docker build -t "$IMAGE_NAME" -f "$DOCKERFILE" "$DOCKERFILE_DIR" 2>&1 || echo "Build failed or skipped" >&2
    fi
  fi
fi
exit 0

Troubleshooting

Docker build fails with daemon not running error despite Docker Desktop being active

Verify Docker socket accessibility with docker info command. Restart Docker daemon or add user to docker group on Linux: sudo usermod -aG docker $USER then log out and back in. Check Docker Desktop is running and Docker socket is accessible: docker ps.

Hook triggers rebuild but uses wrong Dockerfile when multiple exist in project

Specify Dockerfile path explicitly using docker build -f $FILE_PATH instead of relying on directory context. Detect Dockerfile name pattern and use as -f argument for targeted builds. Use absolute paths for Dockerfile specification to avoid ambiguity.

Docker Compose rebuild hangs indefinitely when services have dependency conflicts

Add --no-cache flag to force clean rebuild: docker compose build --no-cache. Stop running containers first with docker compose down before rebuild to prevent port and resource conflicts. Check service dependencies in docker-compose.yml for circular dependencies.

Build context too large error when .dockerignore changes not respected in hook

Ensure .dockerignore is in same directory as Dockerfile being built. Docker reads .dockerignore from build context root, not from Dockerfile directory if using -f flag with different path. Verify .dockerignore location matches build context root directory.

Hook exits successfully but image not updated with latest changes after rebuild

Verify Docker build cache invalidation by checking layer hashes in build output. Add COPY instruction for modified files or use docker build --pull --no-cache to force complete rebuild without cache. Check if BuildKit cache is interfering: DOCKER_BUILDKIT=0 docker build.

Docker Compose v2 (docker compose) not detected despite installation

Verify Docker Compose v2 installation: docker compose version. Check Docker Engine version is 20.10.13+ for native compose support. Use docker compose instead of docker-compose for v2. Verify PATH includes Docker binary location.

BuildKit builds fail with cache mount errors

Ensure BuildKit is enabled: export DOCKER_BUILDKIT=1. Check Docker Engine version supports BuildKit (20.10+). Verify cache mount syntax in Dockerfile is correct. Use --progress=plain for detailed BuildKit error messages.

Multiple Docker Compose files not handled correctly by hook

Detect all compose files in project: find . -name docker-compose*.yml. Use -f flag to specify compose file explicitly: docker compose -f docker-compose.dev.yml build. Support multiple compose files: docker compose -f docker-compose.yml -f docker-compose.override.yml build.

Source citations

Add this badge to your README

Show that Docker Container Auto Rebuild - Hooks is listed on HeyClaude. Paste this Markdown into your README — it renders the badge and links back to this page.

Listed on HeyClaude
[![Listed on HeyClaude](https://heyclau.de/badge/hooks/docker-container-auto-rebuild.svg)](https://heyclau.de/entry/hooks/docker-container-auto-rebuild)

How it compares

Docker Container Auto Rebuild - Hooks side by side with 3 alternatives on trust, install, platform support, and disclosed safety notes — all from reviewed registry metadata.

Field

A PostToolUse hook that watches for edits to Docker-related files (Dockerfile, docker-compose, .dockerfile, .dockerignore).

Open dossier

Comprehensive Docker image vulnerability scanning with layer analysis, base image recommendations, and security best practices enforcement. This PostToolUse hook automatically scans Docker images for vulnerabilities when Dockerfiles are modified, providing real-time security validation during development.

Open dossier

Automatically creates timestamped backups of files before modification to prevent data loss. This hook runs before file editing operations (Edit, Write, Multiedit) and creates versioned backups in a centralized .backups directory with ISO 8601-compliant timestamps including nanoseconds for collision prevention.

Open dossier

Validates Kubernetes YAML manifests for syntax and best practices when modified.

Open dossier
Next steps
Trust
Review statusReviewedMaintainer reviewedReviewedMaintainer reviewedReviewedMaintainer reviewedReviewedMaintainer reviewed
Package trustPackage not verifiedPackage not verifiedPackage not verifiedPackage not verified
Source provenanceSource-backedSource-backedSource-backedSource-backed
Submitter
Install riskReview firstReview firstReview firstReview first
Notes Safety Privacy Safety Privacy Safety Privacy Safety Privacy
BrandDocker logoDockerDocker logoDockerKubernetes logoKubernetes
Categoryhookshookshookshooks
Sourcesource-backedsource-backedsource-backedsource-backed
AuthorJSONboredJSONboredJSONboredJSONbored
Added2025-09-192025-10-192025-09-192025-09-19
Platforms
Claude Code
Claude Code
Claude Code
Claude Code
Source repo
Safety notesRuns automatically after write or edit activity on Dockerfile, docker-compose, dockerfile, and dockerignore paths. Invokes docker build or docker compose build and can consume CPU, disk, network, and local Docker daemon resources. Uses the Dockerfile directory or compose-file directory as the build context, so incorrect paths can include more files than expected.Runs automatically on its configured Claude Code hook event and executes shell logic that can read, modify, or delete files in your project (and may run builds, installs, or network calls); review the script and scope it to expected paths before enabling.Runs automatically on its configured Claude Code hook event and executes shell logic that can read, modify, or delete files in your project (and may run builds, installs, or network calls); review the script and scope it to expected paths before enabling.Runs automatically on its configured Claude Code hook event and executes shell logic that can read, modify, or delete files in your project (and may run builds, installs, or network calls); review the script and scope it to expected paths before enabling.
Privacy notesReads Docker-related files and may send build context files to the local Docker daemon during image builds. Build logs may reveal image names, service names, dependency URLs, and package-install output. Prints the first lines of .dockerignore files to local hook output when those files are edited.Receives Claude Code hook input (session metadata, file paths, and tool output) and reads local project files; review what the script logs or forwards to external services and keep credentials out of its output.Receives Claude Code hook input (session metadata, file paths, and tool output) and reads local project files; review what the script logs or forwards to external services and keep credentials out of its output.Receives Claude Code hook input (session metadata, file paths, and tool output) and reads local project files; review what the script logs or forwards to external services and keep credentials out of its output.
Prerequisites— none listed— none listed— none listed— none listed
Install
mkdir -p .claude/hooks && touch .claude/hooks/docker-container-auto-rebuild.sh && chmod +x .claude/hooks/docker-container-auto-rebuild.sh
mkdir -p .claude/hooks && touch .claude/hooks/docker-image-security-scanner.sh && chmod +x .claude/hooks/docker-image-security-scanner.sh
mkdir -p .claude/hooks && touch .claude/hooks/auto-save-backup.sh && chmod +x .claude/hooks/auto-save-backup.sh
mkdir -p .claude/hooks && touch .claude/hooks/kubernetes-manifest-validator.sh && chmod +x .claude/hooks/kubernetes-manifest-validator.sh
Config
{
  "hooks": {
    "postToolUse": {
      "script": "./.claude/hooks/docker-container-auto-rebuild.sh",
      "matchers": [
        "write",
        "edit"
      ]
    }
  }
}
{
  "hooks": {
    "postToolUse": {
      "script": "./.claude/hooks/docker-image-security-scanner.sh",
      "matchers": [
        "write",
        "edit"
      ]
    }
  }
}
{
  "hooks": {
    "preToolUse": {
      "script": "./.claude/hooks/auto-save-backup.sh",
      "matchers": [
        "edit",
        "write",
        "multiedit"
      ]
    }
  }
}
{
  "hooks": {
    "postToolUse": {
      "script": "./.claude/hooks/kubernetes-manifest-validator.sh",
      "matchers": [
        "write",
        "edit"
      ]
    }
  }
}
Citations
ClaimUnclaimedUnclaimedUnclaimedUnclaimed
Open 4 picks in the interactive comparison tool

Related guides

Signals

Loading live community signals…

More like this, weekly

A short, calm digest of reviewed Claude resources. Unsubscribe any time.