Docker FAQ
This page lists common issues and solutions for Docker installation and usage.
Installation Issues
Docker Desktop Fails to Start
Symptoms: Docker Desktop won't start, or crashes immediately after starting
Solutions:
Ensure system meets hardware requirements:
- Windows: Enable Hyper-V or install WSL 2
- Mac: Ensure not using outdated Mac models
Reset Docker Desktop:
- Windows: Right-click Docker icon → Troubleshoot → Reset to factory defaults
- Mac: Docker → Troubleshoot → Reset to factory defaults
Reinstall Docker Desktop
WSL2 Installation Fails
Symptoms: On Windows, prompt says WSL2 not properly installed
Solutions:
Enable Windows features:
- Open "Windows Features"
- Enable "Virtual Machine Platform" and "Windows Subsystem for Linux"
Install WSL2 kernel update package:
- Download and install WSL2 Linux kernel update package
Set WSL2 as default version:
wsl --set-default-version 2
Permission Denied on Linux
Symptoms: "permission denied" when running docker commands
Solutions:
Add current user to docker group:
sudo usermod -aG docker $USERLog out and log back in or restart system
Verify:
docker ps
Virtual Machine Issues
Symptoms: Poor performance or unable to run Docker in virtual machines
Solutions:
- Ensure virtualization is enabled (in BIOS)
- Allocate sufficient CPU and memory to the virtual machine
- Use Docker Desktop instead of Docker Engine
Image Issues
Pulling Images Fails
Symptoms: docker pull command times out or fails
Solutions:
Check network connection
Use domestic mirror sources (configure Docker registry mirrors):
sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<EOF { "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"] } EOF sudo systemctl daemon-reload sudo systemctl restart dockerCheck if firewall or proxy is blocking connection
Image Too Large
Solutions:
- Use multi-stage builds to reduce image size
- Choose smaller base images (like alpine versions)
- Clean build cache:
docker builder prune
Clean Up Unused Images
# Delete dangling images (untagged)
docker image prune
# Delete all unused images
docker image prune -a
# Delete build cache
docker builder prune
Container Issues
Container Won't Start
Symptoms: Container stops immediately after creation
Solutions:
View container logs:
docker logs <container name>Check if CMD or ENTRYPOINT in Dockerfile is correct
Ensure there's a foreground process running:
docker run -d nginx tail -f /dev/null
Port Conflicts
Symptoms: Error "port is already allocated" when starting container
Solutions:
Find process using the port:
# Linux sudo lsof -i :8080 # Windows netstat -ano | findstr :8080Stop the process using the port, or use a different port
Modify container port mapping:
docker run -d -p 8081:80 nginx
Containers Can't Communicate
Solutions:
Ensure containers are on the same network:
docker network ls docker network inspect <network name>Use service names for communication (in Docker Compose or same network)
Check container firewall settings
Data Loss
Symptoms: Data lost after container deletion
Solutions:
Use volumes to persist data:
docker run -d -v mydata:/app/data myimageRegularly backup volumes:
docker run --rm -v mydata:/data -v $(pwd):/backup alpine tar czf /backup/backup.tar.gz /data
Container Encoding Issues
Solutions:
Set locale in Dockerfile:
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
Or use base images with Chinese support.
Network Issues
Cannot Access External Network
Solutions:
Check Docker network configuration:
docker network inspect bridgeCheck DNS settings:
docker run --dns 8.8.8.8 alpine ping -c 3 google.comCheck firewall or proxy settings
Proxy Issues
If you need proxy to access external networks, configure proxy:
# Create Docker config directory
sudo mkdir -p /etc/systemd/system/docker.service.d
# Create proxy config file
sudo tee /etc/systemd/system/docker.service.d/http-proxy.conf <<EOF
[Service]
Environment="HTTP_PROXY=http://proxy.example.com:80"
Environment="HTTPS_PROXY=http://proxy.example.com:443"
Environment="NO_PROXY=localhost,127.0.0.1"
EOF
# Restart Docker
sudo systemctl daemon-reload
sudo systemctl restart docker
Performance Issues
Docker Running Slowly
Solutions:
Allocate more resources to Docker Desktop:
- Docker Desktop → Settings → Resources
Move Docker images to larger disk space
Clean up unused containers, images, and volumes:
docker system prune -a
Insufficient Disk Space
Solutions:
Check disk usage:
docker system dfClean build cache:
docker builder pruneClean unused volumes:
docker volume pruneMove Docker data directory to another disk (requires reconfiguration)
Docker Compose Issues
Services Won't Start
Solutions:
View detailed logs:
docker-compose logs -f <service name>Check docker-compose.yml syntax
Ensure all dependent services are started
Environment Variables Not Taking Effect
Solutions:
Properly set environment in docker-compose.yml:
environment: - NODE_ENV=production # or environment: NODE_ENV: productionCheck if .env file exists
Port Conflicts
Same as single containers, docker-compose may also encounter port conflicts. Modify port mapping in docker-compose.yml.
Uninstallation Issues
Completely Uninstall Docker
Ubuntu/Debian:
# Stop Docker service
sudo systemctl stop docker
# Uninstall Docker packages
sudo apt-get purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# Remove data and config
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
# Remove user group
sudo groupdel docker
# Remove config files
sudo rm -rf /etc/docker
macOS:
# Stop Docker
osascript -e 'quit app "Docker"'
# Remove application
rm -rf /Applications/Docker
# Remove config and data
rm -rf ~/Library/Containers/com.docker.docker
rm -rf ~/Library/Application\ Support/Docker
rm -rf ~/Library/Group\ Containers/group.com.docker
Windows:
Uninstall Docker Desktop through Settings → Apps, or use Control Panel.
Other Issues
How to Check Docker Version
docker --version
docker-compose --version
docker-machine --version
How to Get Help
- Docker Official Documentation: https://docs.docker.com/
- Docker Hub: https://hub.docker.com/
- Docker Community: https://www.docker.com/community/
- View command help:
docker --help
Docker Command Not Found
Make sure Docker is properly installed and added to PATH. Check:
which docker
echo $PATH
If not in PATH, add to shell config file.
Containers Auto Restart
Use --restart option:
docker run -d --restart=always nginx
Restart policies include:
no: No auto restarton-failure: Restart on failurealways: Always restartunless-stopped: Always restart unless manually stopped
Limit Container Resources
# Limit memory
docker run -d --memory="512m" nginx
# Limit CPU
docker run -d --cpus="1.5" nginx
# Limit memory and CPU
docker run -d --memory="512m" --cpus="1.5" nginx
