DEV Community

Kamrul Hasan
Kamrul Hasan

Posted on

3 3 2 2 1

Check Docker Installation Details- Part 4

Troubleshooting Common Docker Issues

Image description

Issue: Docker Daemon Not Running

If you attempt to run a Docker command and encounter an error such as:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

This indicates that the Docker daemon isn't running. To fix this:

1.Verify the status of the Docker service by running:

# systemctl status docker
Enter fullscreen mode Exit fullscreen mode

2.If it's not running, start the Docker service with the following command:

# systemctl start docker
Enter fullscreen mode Exit fullscreen mode

3.If the service fails to start, examine the logs for error messages using:

# journalctl -u docker
Enter fullscreen mode Exit fullscreen mode

Let’s walk through a simulated scenario of this issue and how to resolve it:

## First, stop the Docker service to simulate the issue

    # systemctl stop docker

## Try to run a Docker command

    # docker ps

## You'll see the "Cannot connect" error
## Now restart the service to fix it

    # systemctl start docker

## Verify Docker is working again

    # docker ps
Enter fullscreen mode Exit fullscreen mode

Issue: Permission Denied

If you encounter an error such as: Got permission denied while trying to connect to the Docker daemon socket.

This typically indicates that your user lacks permission to access the Docker socket. To resolve this, add your user to the docker group:

# usermod -aG docker $USER

Enter fullscreen mode Exit fullscreen mode

After executing this command, you’ll usually need to log out and log back in for the changes to take effect.

Issue: Disk Space Problems

Over time, Docker can use up a considerable amount of disk space due to unused images, containers, and volumes. If you notice your system is low on disk space

1.Inspect Docker's disk usage with:

# docker system df
Enter fullscreen mode Exit fullscreen mode

2.Remove unused resources:

## Remove all stopped containers
    # docker container prune

## Remove all unused images
    # docker image prune

## Remove all unused volumes
    # docker volume prune

## Or remove everything unused in one command
    # docker system prune
Enter fullscreen mode Exit fullscreen mode

Let's walk through how to use the pruning command:

## Create some containers that will exit immediately
    # docker run hello-world
    # docker run ubuntu echo "This will exit immediately"

## Now prune stopped containers
    # docker container prune
Enter fullscreen mode Exit fullscreen mode

You'll be asked to confirm the operation:
WARNING! This will remove all stopped containers. Are you sure you want to continue? [y/N] y
Type y to confirm. You should see output showing the removed containers.

Issue: Container Not Starting

If a container fails to start, you can investigate by checking its logs:

## First, try to start a container that might fail
    # docker run --name failing-container ubuntu apt-get update

## Check the logs
    # docker logs failing-container
You might see errors in the logs that indicate why the container failed.
Enter fullscreen mode Exit fullscreen mode

Issue: Network Problems

If containers are unable to communicate with one another or with external networks:
1.Inspect Docker’s network settings:

# docker network ls
Enter fullscreen mode Exit fullscreen mode

2.Inspect a specific network:

# docker network inspect bridge
Enter fullscreen mode Exit fullscreen mode
## 3.Test connectivity from within a container:

## Start a container with networking
    # docker run -it ubuntu bash
## From inside the container, install ping
    # apt-get update && apt-get install -y iputils-ping
## Try pinging a website
    # ping google.com
## Exit the container
    # exit
Enter fullscreen mode Exit fullscreen mode

Docker Logs and Debugging

For overall Docker troubleshooting, reviewing the Docker daemon logs can provide valuable insights:

# journalctl -u docker
Enter fullscreen mode Exit fullscreen mode

For a specific container's logs:

# docker logs <container_id>
Enter fullscreen mode Exit fullscreen mode

You can also get a real-time stream of logs:

# docker logs -f <container_id>
Enter fullscreen mode Exit fullscreen mode

These troubleshooting steps can help you identify and fix most common Docker problems.

Md. Kamrul Hasan

https://linkedin.com/in/kamrul-dev
https://github.com/kamrul-dev

Related Keywords:
common Docker issues and fixes,
how to troubleshoot Docker problems,
Docker daemon not running fix,
Docker container network issues,
Docker permission denied socket,
Docker disk space cleanup,
Docker prune command example,
Docker troubleshooting commands,
check Docker service status Linux,
Docker logs for debugging,

Top comments (6)

Collapse
 
nevodavid profile image
Nevo David

pretty cool seeing real fixes explained like this - makes me wonder if learning through constant trial and error actually sticks better for you too

Collapse
 
kamruldev profile image
Kamrul Hasan

Thank you and appreciated.

Collapse
 
kmcoursedev profile image
Hasan

Awesome tutorial for beginners to trouble shooting docker container , Learned something great.

Collapse
 
kamruldev profile image
Kamrul Hasan

I am so glad to hear from you.. stay connected

Collapse
 
nathan_tarbert profile image
Nathan Tarbert

This is honestly the kind of guide I wish I had in my early days - super clear, no fluff.

Collapse
 
kamruldev profile image
Kamrul Hasan

Thanks so much! That means a lot—glad it hit the mark. I made it with that exact goal in mind: something I wish I had starting out too.