What's Actually Happening

Skaffold fails to build container images. The build process errors out during image construction or push.

The Error You'll See

```bash $ skaffold build

Building [my-image]... Error: build failed: failed to build image: docker build failed ```

Dockerfile error:

bash
Error: failed to solve: process "/bin/sh -c apt-get install" did not complete successfully

Registry push error:

bash
Error: failed to push image: denied: requested access to the resource is denied

Context error:

bash
Error: failed to read dockerfile: open Dockerfile: no such file or directory

Why This Happens

  1. 1.Dockerfile error - Invalid Dockerfile syntax or commands fail
  2. 2.Build context wrong - Missing files or wrong directory
  3. 3.Registry auth failed - Not logged into container registry
  4. 4.Docker daemon issue - Docker not running or misconfigured
  5. 5.Resource limits - Build runs out of memory or disk
  6. 6.Network issues - Cannot reach base images or registry

Step 1: Check Skaffold Configuration

```bash # View Skaffold config: cat skaffold.yaml

# Validate skaffold.yaml: skaffold verify

# Check build artifacts: skaffold build --dry-run

# Show build configuration: skaffold build --verbosity=debug

# List build artifacts: skaffold build --file-output=build.json

# Check profiles: skaffold build --profile=production

# Check artifact definitions: cat skaffold.yaml | grep -A20 "build:"

# Typical build config: build: artifacts: - image: my-image docker: dockerfile: Dockerfile context: . target: build ```

Step 2: Test Docker Build Locally

```bash # Test Docker build manually: docker build -t my-image:local .

# Build with Dockerfile path: docker build -t my-image:local -f Dockerfile .

# Build with context: docker build -t my-image:local -f ./app/Dockerfile ./app

# Build specific target: docker build -t my-image:local --target build .

# Build with no cache: docker build -t my-image:local --no-cache .

# Build with build args: docker build -t my-image:local --build-arg VERSION=v1.0.0 .

# Verbose Docker build: docker build -t my-image:local --progress=plain .

# Check Docker daemon: docker info

# Check Docker version: docker version ```

Step 3: Fix Dockerfile Issues

```bash # Check Dockerfile syntax: hadolint Dockerfile

# Common Dockerfile issues:

# 1. Invalid FROM: # BAD: FROM ubunto:latest # Typo # GOOD: FROM ubuntu:latest

# 2. Missing package manager update: # BAD: RUN apt-get install package # GOOD: RUN apt-get update && apt-get install -y package

# 3. Invalid COPY/ADD path: # BAD: COPY ../app /app # Can't go outside context # GOOD: COPY app /app

# 4. Command not found: # BAD: RUN npm install # npm not installed # GOOD: FROM node:18 RUN npm install

# 5. Permission denied: # BAD: RUN apt-get install # Non-root # GOOD: USER root RUN apt-get install

# Test Dockerfile step by step: docker build -t test --target=step1 . docker build -t test --target=step2 . ```

Step 4: Check Build Context

```bash # Verify files in context: ls -la .

# Check if Dockerfile exists: ls Dockerfile

# Check Dockerfile path in skaffold.yaml: cat skaffold.yaml | grep dockerfile

# Use .dockerignore to speed up: cat .dockerignore # node_modules # .git # target

# Check context path: cat skaffold.yaml | grep context

# Absolute vs relative path: # Relative (preferred): # context: ./app # Absolute: # context: /home/user/project/app

# Verify required files exist: ls -la ./app/Dockerfile ls -la ./app/package.json

# Check for large files: find . -type f -size +50M

# Exclude large files: echo "*.tar.gz" >> .dockerignore ```

Step 5: Fix Registry Authentication

```bash # Check current registry: cat skaffold.yaml | grep registry

# Login to Docker registry: docker login

# Login to specific registry: docker login gcr.io docker login quay.io docker login myregistry.com

# Login with token: echo $TOKEN | docker login -u user --password-stdin gcr.io

# Check Docker config: cat ~/.docker/config.json

# Verify credentials: cat ~/.docker/config.json | jq '.auths.gcr.io'

# For GCR: gcloud auth configure-docker

# For ECR: aws ecr get-login-password | docker login --username AWS --password-stdin $AWS_ACCOUNT.dkr.ecr.$REGION.amazonaws.com

# For ACR: az acr login --name myregistry

# Configure Skaffold registry: # skaffold.yaml: build: artifacts: - image: gcr.io/my-project/my-image local: push: true ```

Step 6: Check Docker Daemon

```bash # Check Docker status: systemctl status docker

# Start Docker: systemctl start docker

# Check Docker logs: journalctl -u docker

# Check Docker disk space: docker system df

# Clean up Docker: docker system prune -a

# Check Docker daemon config: cat /etc/docker/daemon.json

# Increase Docker resources (Docker Desktop): # Settings -> Resources -> Memory: 8GB

# Check Docker buildx: docker buildx version

# Create buildx builder: docker buildx create --use --name mybuilder

# Check builder: docker buildx inspect mybuilder

# Restart Docker daemon: sudo systemctl restart docker ```

Step 7: Handle Multi-Architecture Builds

```bash # Check buildx platforms: docker buildx inspect --bootstrap

# Build for multiple platforms: skaffold build --platform=linux/amd64,linux/arm64

# Configure in skaffold.yaml: build: artifacts: - image: my-image platforms: - linux/amd64 - linux/arm64

# Test single platform: skaffold build --platform=linux/amd64

# Check QEMU setup: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes

# Buildx build for arm64: docker buildx build --platform linux/arm64 -t my-image:arm64 . ```

Step 8: Check Build Resource Limits

```bash # Check available resources: docker info | grep -i memory

# Increase Docker memory: # Docker Desktop -> Settings -> Resources

# Check disk space: df -h /var/lib/docker

# Clean up disk: docker system prune -a --volumes

# Set build memory limit: # In Docker daemon.json: { "max-concurrent-downloads": 3, "max-concurrent-uploads": 3 }

# Configure Skaffold resources: # skaffold.yaml: build: local: concurrency: 2

# Check for OOM during build: dmesg | grep -i "out of memory"

# Increase container build memory: export DOCKER_BUILDKIT=1 export COMPOSE_DOCKER_CLI_BUILD=1 ```

Step 9: Fix Network Issues

```bash # Test internet connectivity: ping -c 3 google.com

# Check Docker network: docker network ls

# Test registry access: curl -I https://registry-1.docker.io/v2/

# Check proxy settings: echo $HTTP_PROXY echo $HTTPS_PROXY echo $NO_PROXY

# Configure Docker proxy: # ~/.docker/config.json: { "proxies": { "default": { "httpProxy": "http://proxy:8080", "httpsProxy": "http://proxy:8080", "noProxy": "localhost,127.0.0.1" } } }

# Or in daemon.json: { "proxies": { "default": { "httpProxy": "http://proxy:8080" } } }

# Test pulling base image: docker pull ubuntu:latest

# DNS issues: cat /etc/resolv.conf

# Add DNS to daemon.json: { "dns": ["8.8.8.8", "8.8.4.4"] } ```

Step 10: Skaffold Build Verification Script

```bash # Create verification script: cat << 'EOF' > /usr/local/bin/check-skaffold-build.sh #!/bin/bash

echo "=== Skaffold Config ===" cat skaffold.yaml | head -50

echo "" echo "=== Docker Status ===" docker info | head -20

echo "" echo "=== Docker Disk ===" docker system df

echo "" echo "=== Registry Login ===" cat ~/.docker/config.json | jq '.auths' 2>/dev/null || echo "No Docker config"

echo "" echo "=== Build Context ===" ls -la .

echo "" echo "=== Dockerfile ===" cat Dockerfile 2>/dev/null || echo "No Dockerfile in current dir"

echo "" echo "=== .dockerignore ===" cat .dockerignore 2>/dev/null || echo "No .dockerignore"

echo "" echo "=== Test Build ===" skaffold build --dry-run 2>&1 | head -20

echo "" echo "=== Docker Build Test ===" docker build -t test-build . --no-cache 2>&1 | tail -20

echo "" echo "=== Recommendations ===" echo "1. Fix any Dockerfile syntax errors" echo "2. Ensure Docker daemon is running" echo "3. Login to container registry" echo "4. Check build context files exist" echo "5. Verify network connectivity" echo "6. Free disk space if needed" echo "7. Increase Docker memory limits" EOF

chmod +x /usr/local/bin/check-skaffold-build.sh

# Usage: /usr/local/bin/check-skaffold-build.sh ```

Skaffold Build Checklist

CheckExpected
Dockerfile syntaxValid, builds locally
Build contextFiles present
Docker runningDaemon healthy
Registry authLogged in
Disk spaceAdequate for layers
NetworkCan pull base images
ResourcesMemory/CPU sufficient

Verify the Fix

```bash # After fixing Skaffold build issues

# 1. Test Docker build docker build -t my-image:test . // Build successful

# 2. Test Skaffold build skaffold build // Build and push successful

# 3. Check image in registry docker pull gcr.io/my-project/my-image:latest // Image pulled

# 4. Run Skaffold dev skaffold dev // Continuous build works

# 5. Deploy to cluster skaffold run // Deployment successful

# 6. Check built image docker images | grep my-image // Image listed with correct tag ```

  • [Fix Docker Compose Up Failed](/articles/fix-docker-compose-up-failed)
  • [Fix Docker Image Not Found](/articles/fix-docker-image-not-found)
  • [Fix Docker Registry Push Denied](/articles/fix-docker-registry-push-denied)