0% found this document useful (0 votes)
163 views28 pages

Docker Practice Kit

The Docker Troubleshooting Guide provides solutions for common Docker issues, including problems with the Docker daemon, permissions, pulling images, and container accessibility. Each issue is accompanied by specific error messages and step-by-step solutions to resolve them. The guide also covers advanced topics like Docker Compose errors, network issues, and resource limitations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
163 views28 pages

Docker Practice Kit

The Docker Troubleshooting Guide provides solutions for common Docker issues, including problems with the Docker daemon, permissions, pulling images, and container accessibility. Each issue is accompanied by specific error messages and step-by-step solutions to resolve them. The guide also covers advanced topics like Docker Compose errors, network issues, and resource limitations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

DevOps Shack

DOCKER TROUBLESHOOTING GUIDE

1. Docker Daemon Not Running


Error:

Cannot connect to the Docker daemon at


unix:///var/run/docker.sock. Is the docker
daemon running?

Solution:

Start the Docker daemon:​



sudo systemctl start docker​

Enable it at boot:​

sudo systemctl enable docker

If Docker is already running but still shows this error, restart it:​

sudo systemctl restart docker

2. Permission Denied When Running Docker


Error:

Got permission denied while trying to connect


to the Docker daemon socket

Solution:

Add your user to the docker group:​



sudo usermod -aG docker $USER​

Restart your session:​



newgrp docker

●​ If issues persist, restart Docker.


3. Docker Fails to Pull Image


Error:

Error response from daemon: Get


https://registry-1.docker.io/v2/: net/http:
request canceled

Solution:

●​ Check your internet connection.

If using a corporate proxy, configure Docker with proxy settings in


/etc/systemd/system/docker.service.d/http-pro
xy.conf:​
ini​

[Service]
Environment="HTTP_PROXY=http://proxy.example.
com:80/"​

Restart Docker:​

sudo systemctl daemon-reload​

sudo systemctl restart docker

4. Docker Container Exits Immediately


Error:

Exited (0)

Solution:

Run with -it to keep the container interactive:​




docker run -it ubuntu

●​ If running a script, ensure the script doesn’t exit


immediately.

5. Port is Already in Use


Error:

Error response from daemon: driver failed


programming external connectivity on endpoint


Solution:

Find the process using the port:​



sudo lsof -i :<PORT>

Kill the process:​




sudo kill -9 <PID>

●​ Restart the container.

6. Container is Not Accessible from Host


Error:

Cannot reach the container from the host

Solution:

Ensure the port is mapped correctly:​



docker run -p 8080:80 nginx

Check firewall settings:​



sudo ufw allow 8080

7. Docker Build Fails Due to Permissions


Error:

EACCES: permission denied

Solution:

Use --no-cache during build:​




docker build --no-cache -t myimage .

Ensure correct permissions:​




sudo chmod -R 755 .
8. Docker Out of Space
Error:

No space left on device

Solution:

Clean unused Docker objects:​




docker system prune -a

●​ Increase disk space.

9. Docker Container Logs Are Too Large


Error:

Log files consuming too much space

Solution:

Limit log file size in /etc/docker/daemon.json:​


Json​




{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
}
}
Restart Docker:​

sudo systemctl restart docker

10. Container Fails to Restart


Error:

Container keeps craing on restart

Solution:

Check logs:​

docker logs <container_id>​

Run in interactive mode for debugging:​






docker run -it --entrypoint /bin/ mycontainer

11. Docker Network Not Found


Error:

Error response from daemon: network not found

Solution:

List networks:​

docker network ls​

Recreate the network:​



docker network create mynetwork

12. Cannot Stop a Running Container


Error:

Container does not stop

Solution:​




Force stop:​

docker kill <container_id>

If that fails, restart Docker:​



sudo systemctl restart docker

13. Docker Compose Not Found


Error:

docker-compose: command not found

Solution:

Install Docker Compose:​



sudo apt install docker-compose -y

14. Container Can't Connect to Internet


Error:

Network unreachable​

Solution:

Restart the Docker network:​



docker network disconnect bridge
<container_id>
docker network connect bridge <container_id>​

Check if DNS settings are correct in


/etc/docker/daemon.json:​
json​

{
"dns": ["8.8.8.8", "8.8.4.4"]
}

15. Docker Image Too Large


Error:

Image size too large

Solution:​




●​ Reduce layers in Dockerfile.

Use alpine-based images:​



FROM alpine

16. Docker Build Fails Due to Proxy Issues


Error:

Failed to fetch https://some-url.com

Solution:

If behind a proxy, set the proxy in Dockerfile:​


Dockerfile​

ENV http_proxy=http://proxy.example.com:80/
ENV https_proxy=http://proxy.example.com:80/

Or configure system-wide proxy settings:​


export
HTTP_PROXY=http://proxy.example.com:80/​


export
HTTPS_PROXY=http://proxy.example.com:80/

17. Container Cannot Resolve Hostnames


Error:

Temporary failure in name resolution

Solution:

Check network settings:​



docker network inspect bridge
Add a DNS server in /etc/docker/daemon.json:​
json​

{
"dns": ["8.8.8.8", "8.8.4.4"]
}
Restart Docker:​

sudo systemctl restart docker

18. Error Binding Ports on Mac​




Error:

Bind for 0.0.0.0:80 failed: port is already


allocated

Solution:

Find the process using the port:​



lsof -i :80
Kill the process:​

kill -9 <PID>

19. Dockerfile COPY Command Fails


Error:

COPY failed: no source files were found

Solution:

●​ Ensure files exist relative to Dockerfile.

Use absolute paths:​


Dockerfile​





COPY ./myfile /app/myfile

20. Cannot Remove Docker Image


Error:

Error response from daemon: conflict: unable


to delete

Solution:

Find and remove dependent containers:​



docker ps -a | grep <image_id>
docker rm <container_id>​

Then remove the image:​



docker rmi <image_id>

21. High CPU Usage in Docker Containers


Solution:

Limit CPU usage:​







docker run --cpus=".5" mycontainer

22. Docker Not Recognizing Environment Variables


Error:

Variable not found

Solution:

Pass environment variables explicitly:​



docker run -e MYVAR=value myimage
Use ENV in Dockerfile:​
Dockerfile​

ENV MYVAR=value

23. Docker Container Exceeds Memory Limits


Solution:

Limit memory usage:​



docker run --memory="256m" mycontainer

24. Container Fails to Start Due to Missing File


Error:

No such file or directory

Solution:

Verify volume mounts:​



docker inspect <container_id>

●​ Ensure the file exists in the correct directory.

25. Cannot Attach to Running Container


Error:

You cannot attach to a non-running container

Solution:

Ensure the container is running:​



docker start <container_id>

Attach again:​

docker attach <container_id>

26. Docker Logs Not owing Anything


Solution:

Ensure logging is enabled:​


json​

{
"log-driver": "json-file"
}
Restart Docker:​

sudo systemctl restart docker

27. Containers Not Communicating in Docker Compose


Solution:

Ensure services are in the same network:​


Networks:​



mynetwork:
services:
service1:
networks:
- mynetwork
service2:
networks:
- mynetwork

28. Docker Container Restart Loop


Error:

Restarting (1) 3 seconds ago

Solution:

Check logs:​

docker logs <container_id>

●​ Fix application issues.

29. Docker Image Layer Caching Issues​




Solution:

Force rebuild:​

docker build --no-cache -t myimage .

30. Docker Volume Not Mounting


Solution:

Ensure volume exists:​



docker volume ls
Create a new volume if necessary:​

docker volume create myvolume

31. Docker Container Cannot Write to Mounted Volume


Error:

Permission denied

Solution:

Ensure correct permissions:​


sudo chmod -R 777 /my/host/path​

Use --user to match the container user:​



docker run --user $(id -u):$(id -g) -v
/my/host/path:/container/path myimage

32. Dockerfile RUN Command Fails with ‘Command Not Found’


Error:

/bin/: mycommand: not found

Solution:

Ensure the command is installed:​


Dockerfile​

RUN apt-get update && apt-get install -y
mypackage

33. Dockerfile ENTRYPOINT or CMD Not Executing


Error:

exec: "mycommand": executable file not found


in $PATH​

Solution:

Ensure the script has executable permissions:​


Dockerfile​

RUN chmod +x /my/script.

Specify ell execution:​


Dockerfile​

CMD ["", "-c", "/my/script."]

34. Docker Compose ‘Service Not Found’ Error


Error:

Service "myservice" not found

Solution:

Ensure correct indentation in docker-compose.yml:​


yaml​
services:
Myservice:​

image: myimage

●​ Use docker-compose up -d --build to rebuild.

35. ‘OCI Runtime Permission Denied’ Error


Error:

OCI runtime permission denied

Solution:

If running as a non-root user, add --privileged:​



docker run --privileged myimage

36. Cannot Connect to MySQL/PostgreSQL Container


Error:

Access denied for user 'root'@'localhost'

Solution:

Ensure the correct environment variables:​


docker run -e
MYSQL_ROOT_PASSWORD=mysecretpassword mysql



37. Docker Volume Data Lost After Restart


Solution:

Use named volumes:​



docker run -v myvolume:/data myimage

●​ Ensure volume is not removed with docker volume


prune.

38. Dockerfile COPY Ignores Some Files


Solution:

Check .dockerignore:​

node_modules/
logs/

39. Docker Build Hangs Indefinitely


Solution:

Run with debug logs:​


DOCKER_BUILDKIT=1 docker build
--progress=plain -t myimage .

40. Docker Compose Up Fails with ‘No Such File or Directory’


Solution:

Ensure the file exists relative to the compose file:​


yaml​
volumes:
- ./localpath:/containerpath

41. ‘Exec Format Error’ When Running a Container


Error:

standard_init_linux.go:228: exec user process


caused "exec format error"

Solution:

Ensure the correct architecture:​



uname -m
Rebuild for the correct platform:​
docker build --platform linux/amd64 -t
myimage .​


42. Docker Hub Rate Limits Reached


Error:

css
Too many requests to Docker Hub

Solution:

Authenticate with Docker Hub:​


docker login

●​ Use an alternate registry.

43. ‘Mounts Denied’ on macOS


Error:

Mounts denied: The path is not ared from the


host

Solution:

●​ Add the path to Docker Desktop > Settings > Resources > File
aring.

44. ‘Cannot Start Service’ in Docker Compose


Solution:​




Ensure port is not in use:​


sudo lsof -i :<PORT>

45. Docker Build Context Too Large


Solution:

Reduce the build context using .dockerignore:​


.git/
node_modules/

46. Container Craes with ‘Segmentation Fault’


Solution:

Check for memory leaks or out-of-memory issues:​



dmesg | grep -i OOM

47. ‘Invalid Reference Format’ on Docker Pull


Error:

invalid reference format

Solution:

Ensure the correct image format:​







docker pull myimage:latest

48. ‘Cannot Delete Docker Volume’


Solution:

Ensure no containers are using it:​



docker ps -a | grep myvolume
Then remove:​
docker volume rm myvolume

49. ‘Image Not Found’ When Running Container


Solution:

Pull the correct image:​


docker pull myimage:latest

50. Container Restart Policy Not Working


Solution:

●​ Use --restart=always:​
docker run --restart=always myimage

You might also like