TechBuzzPro

Docker Troubleshooting: Fix Common Issues

· 5 min read · Apps & Browsers

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

This guide walks you through diagnosing and fixing the most frequent Docker problems: containers that won't start, image pulls that fail, port conflicts, and performance issues. You'll learn step-by-step commands and checks to get your Docker environment back to a working state quickly.

What You'll Need

  • A working Docker installation (Docker Engine or Docker Desktop)
  • Command-line access (Terminal on macOS/Linux, PowerShell or CMD on Windows)
  • Basic familiarity with running Docker commands
  • For some fixes, sudo/administrator privileges

Step-by-Step

1. Check if Docker is Running

Before anything else, confirm the Docker daemon is active. Run docker info or docker version. If you get an error like "Cannot connect to the Docker daemon," start Docker Desktop (or the service) and wait a few seconds. On Linux, use sudo systemctl start docker if it's not running.

2. Inspect Container Logs

When a container exits immediately or misbehaves, its logs are the first clue. Use docker logs <container_name_or_id> to see output. For a container that has already stopped, add --tail 50 to see the last 50 lines. Look for error messages, missing dependencies, or configuration issues.

3. Check Container Status and Exit Code

Run docker ps -a to list all containers, including stopped ones. Note the STATUS column—if it says "Exited (1)", the exit code (1) often indicates an application error. Compare with typical exit codes: 0 means success, 1 is a general error, 137 means the container was killed (often OOM), 143 means terminated by SIGTERM.

4. Verify Image Availability and Tags

If a pull fails, first check the image name and tag spelling. Use docker search <image> to confirm it exists. If you're pulling a specific version, ensure the tag is correct (e.g., nginx:1.25). For private registries, log in with docker login first.

5. Resolve Port Conflicts

If you see "port is already allocated," another container or host process is using that port. Find the culprit with docker ps (check PORTS column) or sudo lsof -i :<port> on Linux/macOS. Change the host port mapping in your docker run command or docker-compose.yml (e.g., -p 8081:80 instead of -p 8080:80).

6. Free Up Disk Space

Docker can fill your disk with unused images, containers, and volumes. Run docker system df to see usage. Clean up with docker system prune -a (removes all unused images, not just dangling ones) and docker volume prune for orphaned volumes. Be careful—these are destructive.

7. Fix Network Issues

If containers can't reach the internet or each other, check the network. Run docker network ls to list networks. For a container, inspect with docker inspect <container> | grep NetworkMode. Common fixes: use --network host for host networking, or create a custom bridge network with docker network create mynet and connect containers to it.

8. Address Resource Limits

If a container is killed with exit code 137, it may be hitting memory limits. Check current limits with docker inspect <container> | grep -i memory. Run with --memory=2g to increase, or adjust in docker-compose under deploy.resources.limits.

9. Rebuild with --no-cache

Stale cache can cause weird build failures. If a Dockerfile build fails unexpectedly, try docker build --no-cache -t myimage . to force a fresh build. This often resolves issues from outdated base images or cached layers.

10. Restart Docker Daemon

When all else fails, restart Docker. On Docker Desktop, click the whale icon and select Restart. On Linux, sudo systemctl restart docker. This clears transient state and often fixes mysterious issues.

Common Mistakes

  • Using wrong image tag—always specify a version, not just latest, to avoid surprises.
  • Forgetting to rebuild after code changes—editing source files without rebuilding the image will not affect running containers.
  • Ignoring .dockerignore—large unnecessary files bloat the build context and slow builds.
  • Running containers in detached mode without logs—use -d only after you've tested interactively.
  • Not cleaning up—accumulated images and volumes eat disk space and cause performance degradation.

Tips

  • Use docker run --rm for temporary containers to auto-remove them on exit.
  • Always name your containers with --name to make logs and inspection easier.
  • Write a docker-compose.yml for multi-container apps—it simplifies port mapping and network configuration.
  • Use docker top <container> to see running processes inside a container.
  • Keep base images small (e.g., alpine) to reduce pull times and attack surface.

Troubleshooting

If the above steps don't resolve your issue:

  • Check Docker daemon logs—on Linux, journalctl -u docker; on macOS, look in Docker Desktop's logs via the menu.
  • Run a minimal test—try docker run hello-world to isolate whether the problem is with your image or Docker itself.
  • Inspect the container's filesystem—docker exec -it <container> sh to explore inside and test commands manually.
  • Check for SELinux/AppArmor—on Linux, these can block container operations. Temporarily set them to permissive to test, but re-enable after.
  • Verify DNS settings—if pulls fail with DNS errors, configure Docker daemon with dns options in /etc/docker/daemon.json.

Frequently Asked Questions

Why does my container exit immediately?

Most often, the main process inside the container fails or finishes. Check logs with docker logs. For interactive processes, run with -it to keep it alive. Also ensure the Dockerfile CMD or ENTRYPOINT is correct.

How do I fix a port already in use?

Find what's using the port (e.g., lsof -i :8080 on Linux/macOS, or netstat -ano | findstr :8080 on Windows). Stop that process or change the host port mapping in your docker run command.

Why is docker pull so slow?

Try changing the registry mirror in Docker Desktop settings or daemon.json. Also check your internet speed and firewall. Pulling smaller images or using a different tag can help.

How do I remove all unused Docker data?

Use docker system prune -a --volumes to remove all unused images, containers, networks, and volumes. Be careful—this deletes data you might need later.

Can I run Docker on Windows without Hyper-V?

Docker Desktop requires Hyper-V or WSL 2. If you can't use those, try Docker Toolbox (legacy) which uses VirtualBox, but it's outdated. WSL 2 is the recommended approach on Windows 10/11.

Why can't my container connect to the internet?

Check if you're using a custom network that lacks a gateway. Run docker network inspect bridge to see if the default bridge has outbound connectivity. Try --network host to test. Also check your firewall and DNS settings.