Skip to content

How to resolve docker hang or not responsive when using docker ps commands

Problem

When using Docker from the command line, sometimes the Docker commands hang indefinitely without any response. This includes commands like docker info, docker help, docker version, docker ps, and docker images.

Terminal window
root@launch-advisor:~# docker ps
^C
root@launch-advisor:~#

The only way to quit the command is by pressing Ctrl+C.

Environment

  • Docker: Server Version: 19.03.13

Reason

When you use commands like docker info, docker version, docker ps, or docker images, you are actually connecting to the Docker daemon service from the Docker client command, as shown below:

image-20201201202257959

According to the official Docker documentation, the Docker daemon is a service that provides a RESTful web service via a socket:

Docker Engine Components Flow

The Docker Daemon

The Docker daemon (dockerd) listens for Docker API requests and manages Docker objects such as images, containers, networks, and volumes. A daemon can also communicate with other daemons to manage Docker services.

The Docker Client

The Docker client (docker) is the primary way many Docker users interact with Docker. When you use commands like docker run, the client sends these commands to dockerd, which carries them out. The docker command uses the Docker API and can communicate with more than one daemon.

When your Docker command hangs unexpectedly, it could be due to the following issues:

  • Your computer is full of Docker images, exceeding its capacity. If the Docker images are outdated, remove them from your system.
  • The Docker daemon process is stuck for some reason. Check /var/log/syslog for the real reason.

Solution

There are several solutions to resolve this issue:

Solution #1: Remove Unused Docker Images and Logs

The key point of this solution is to remove all unused Docker images and logs from the system:

  1. Remove unused Docker images:

    Terminal window
    docker system prune -a
  2. If the above command hangs, manually remove the Docker root directory:

    Terminal window
    # Get the root directory of Docker images
    docker info | grep 'Docker Root Dir'
    sudo rm -rf <the docker root image directory path>
    # If the above doesn't work, remove the default directory of Docker images
    # Make a backup before running this command
    sudo rm -rf /var/lib/docker
    # Remove runtime files of Docker (make a backup before running this command)
    sudo rm -rf /var/run/docker
  3. If the issue persists, uninstall and reinstall Docker (CentOS example):

    Terminal window
    sudo yum remove docker docker-common docker-selinux docker-engine
  4. Install Docker again:

    Terminal window
    sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo
    sudo yum install docker-ce docker-ce-cli containerd.io
  5. Start Docker:

    Terminal window
    sudo systemctl start docker
  6. Verify your Docker installation:

    Terminal window
    sudo docker run hello-world

Solution #2: Modify Docker Configuration

If Solution #1 doesn’t work, try the following:

  1. Create a new file /etc/systemd/system/docker.service.d/docker.conf with the following contents to remove the -H argument used when starting the daemon by default:

    /etc/systemd/system/docker.service.d/docker.conf
    [Service]
    ExecStart=
    ExecStart=/usr/bin/dockerd
  2. Create a new file /etc/docker/daemon.json with the following contents:

    /etc/docker/daemon.json
    {
    "debug": true,
    "hosts": ["tcp://127.0.0.1:2375"]
    }
  3. Reload the systemctl service:

    Terminal window
    sudo systemctl daemon-reload
    sudo systemctl stop docker.service
    sudo systemctl start docker.service

Solution #3: Reboot Your System

If your Docker version is too old (less than 13), rebooting your system may resolve the issue.

Summary

Docker commands hanging or becoming unresponsive can be frustrating, but the issue is often related to the Docker daemon or system resource constraints. By cleaning up unused Docker images, modifying Docker configurations, or rebooting your system, you can resolve the issue. Regularly monitoring your system’s storage and Docker logs can help prevent this problem in the future.

Final Words + More Resources

My intention with this article was to help others who might be considering solving such a problem. So I hope that’s been the case here. If you still have any questions, don’t hesitate to ask me by email: Email me

Here are also the most important links from this article along with some further resources that will help you in this scope:

Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!