Docker Error Patterns
Common Docker and container errors with diagnosis and solutions.
Docker Error Patterns
Common Docker and container errors with diagnosis and solutions.
Build Errors
Dockerfile parse error
failed to solve: dockerfile parse errorCauses:
- Syntax error in Dockerfile
- Invalid instruction
- Missing required argument
Common Issues:
# Wrong - missing argument
FROM
# Correct
FROM node:18-alpine
# Wrong - instruction case (older Docker)
from node:18
run npm install
# Correct - uppercase instructions
FROM node:18
RUN npm installCOPY failed: file not found
COPY failed: file not found in build contextCauses:
- File doesn't exist
- File is in .dockerignore
- Wrong path (relative to build context)
Diagnosis:
# Check build context
ls -la
# Check .dockerignore
cat .dockerignore
# Build with verbose output
docker build --progress=plain .Solutions:
# Path is relative to build context, not Dockerfile
# If Dockerfile is in root, and file is in root:
COPY package.json .
# If building from parent directory:
# docker build -f app/Dockerfile .
COPY app/package.json .
# Check file exists in build context
# (not in .dockerignore)RUN command failed
ERROR: failed to solve: process "/bin/sh -c npm install" did not complete successfullyDiagnosis:
# Build with no cache to see full output
docker build --no-cache --progress=plain .Common Fixes:
# Add build dependencies
FROM node:18-alpine
RUN apk add --no-cache python3 make g++ # For native modules
COPY package*.json ./
RUN npm install
# Use specific npm version
RUN npm install -g npm@10
RUN npm ci
# Clear npm cache if issues
RUN npm cache clean --forceCannot connect to Docker daemon
Cannot connect to the Docker daemon at unix:///var/run/docker.sockCauses:
- Docker not running
- Permission denied
- Wrong socket path
Solutions:
# Start Docker
# macOS - start Docker Desktop
# Linux
sudo systemctl start docker
# Check status
docker info
# Permission issue - add user to docker group
sudo usermod -aG docker $USER
newgrp docker # Or logout/loginNo space left on device
no space left on deviceSolutions:
# Remove unused resources
docker system prune -a
# Remove all unused images
docker image prune -a
# Remove all stopped containers
docker container prune
# Remove unused volumes
docker volume prune
# Check disk usage
docker system dfRuntime Errors
Container exits immediately
Container exited with code 0/1Diagnosis:
# Check logs
docker logs container_name
# Run interactively
docker run -it image_name /bin/sh
# Check entrypoint
docker inspect image_name | grep -A5 EntrypointCommon Causes:
- No foreground process
# Wrong - runs in background
CMD ["node", "server.js", "&"]
# Correct - runs in foreground
CMD ["node", "server.js"]- Script exits
# Keep container running
CMD ["tail", "-f", "/dev/null"]- Error on startup
# Check exit code
docker inspect container_name --format='{{.State.ExitCode}}'Port already in use
Error: listen EADDRINUSE: address already in use :::3000
Bind for 0.0.0.0:3000 failed: port is already allocatedDiagnosis:
# Find what's using the port
lsof -i :3000
netstat -tulpn | grep 3000
# Find container using port
docker ps --format "table {{.Names}}\t{{.Ports}}"Solutions:
# Use different port
docker run -p 3001:3000 image_name
# Stop container using port
docker stop $(docker ps -q --filter publish=3000)
# Kill process using port
kill $(lsof -t -i:3000)Permission denied
permission denied while trying to connect to the Docker daemon socketSolutions:
# Run with sudo (not recommended for regular use)
sudo docker ps
# Better - add user to docker group
sudo usermod -aG docker $USER
newgrp docker
# Verify
groups | grep dockerOOMKilled
Container killed due to OOM (Out of Memory)Diagnosis:
docker inspect container_name | grep -i oomSolutions:
# Increase memory limit
docker run -m 2g image_name
# In docker-compose.yml
services:
app:
deploy:
resources:
limits:
memory: 2GNetworking Errors
Cannot resolve hostname
Could not resolve host: api.example.comCauses:
- No network access
- DNS not configured
- Network mode issue
Solutions:
# Check container network
docker inspect container_name | grep -A20 NetworkSettings
# Use host network (development)
docker run --network host image_name
# Add DNS server
docker run --dns 8.8.8.8 image_nameConnection refused between containers
Error: connect ECONNREFUSED 172.17.0.2:5432Causes:
- Containers not on same network
- Using wrong hostname
- Target service not ready
Solutions:
# docker-compose.yml - use service names as hostnames
services:
app:
depends_on:
- db
environment:
DATABASE_URL: postgresql://db:5432/mydb # 'db' is the service name
db:
image: postgres# Create network and connect containers
docker network create mynetwork
docker run --network mynetwork --name db postgres
docker run --network mynetwork --name app myapp
# In app, connect to 'db' hostnameNetwork not found
network mynetwork not foundSolutions:
# Create network
docker network create mynetwork
# List networks
docker network ls
# In docker-compose, networks are created automatically
# Or define explicitly:networks:
mynetwork:
driver: bridge
services:
app:
networks:
- mynetworkVolume Errors
Volume mount permission denied
permission denied: '/app/data'Causes:
- Container user can't write to mounted directory
- SELinux/AppArmor blocking
- Host directory permissions
Solutions:
# Check host directory permissions
ls -la /host/path
# Fix permissions
chmod 777 /host/path # Not recommended for production
# Or
chown 1000:1000 /host/path # Match container user ID
# SELinux - add :z or :Z suffix
docker run -v /host/path:/container/path:z image_name
# Run as root (not recommended)
docker run --user root image_name# In Dockerfile - create directory as root, then switch user
RUN mkdir -p /app/data && chown -R node:node /app
USER nodeVolume not found
Error: No such volume: myvolumeSolutions:
# Create volume
docker volume create myvolume
# List volumes
docker volume ls
# In docker-compose
volumes:
myvolume:
services:
app:
volumes:
- myvolume:/app/dataImage Errors
Image not found
Unable to find image 'myimage:latest' locally
Error response from daemon: pull access deniedCauses:
- Image doesn't exist
- Not logged into registry
- Private image without auth
Solutions:
# Check if image exists
docker images | grep myimage
# Login to registry
docker login
docker login registry.example.com
# Pull explicitly
docker pull myimage:latest
# For private registries
docker pull registry.example.com/myimage:latestManifest not found
manifest for image:tag not foundCauses:
- Tag doesn't exist
- Architecture mismatch (arm64 vs amd64)
Solutions:
# Check available tags
docker manifest inspect image_name
# Specify platform
docker pull --platform linux/amd64 image_name
# Build for multiple platforms
docker buildx build --platform linux/amd64,linux/arm64 -t myimage .Docker Compose Errors
Service failed to build
ERROR: Service 'app' failed to buildDiagnosis:
# Build with verbose output
docker-compose build --no-cache --progress=plain appDepends_on not waiting
Connection refused to databaseProblem: depends_on only waits for container start, not service ready.
Solutions:
# Use healthcheck
services:
db:
image: postgres
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5
app:
depends_on:
db:
condition: service_healthy# Or use wait script in app
#!/bin/sh
until pg_isready -h db -p 5432; do
echo "Waiting for database..."
sleep 2
done
exec "$@"Quick Reference Table
| Error | Category | Quick Fix |
|---|---|---|
| Cannot connect to daemon | Setup | Start Docker, check permissions |
| No space left | Disk | docker system prune -a |
| COPY failed | Build | Check path relative to build context |
| Container exits immediately | Runtime | Add foreground process |
| Port already in use | Network | Use different port or stop other container |
| OOMKilled | Memory | Increase memory limit with -m |
| Connection refused between containers | Network | Use same network, service names |
| Volume permission denied | Volume | Fix host permissions, use :z |
| Image not found | Image | docker login, check registry |
| Depends_on not waiting | Compose | Use healthcheck with condition |
Author: davila7, Claude Code templates (davila7). License: MIT.
Shown here with formatting for the web. Keep the author and license notice when you reuse it.
Related entries
There are more like this in the members library
The Claude Code library holds 13,843 entries. Members can search all of them by meaning and read every one in full.