Currently Available: Need a skilled Software Developer for your next project?
Categories
Docker

Is Docker Making Your Computer Slow? Here Is How to Find the Problem

Does your computer fan get loud when you run Docker or your system becomes sluggish? Usually, the problem is not Docker itself, but a process inside one of your containers that is using too many resources.

This guide will show you how to find and fix the problem in three simple steps.

Step 1: See What Docker Is Doing with docker stats

The most important tool you have is docker stats. It is a live dashboard that shows how much CPU, memory, and disk your containers are using. You don't need to install anything to use it.

Open your terminal and run this command:

docker stats

You will see a live table like this:

CONTAINER ID   NAME               CPU %     MEM USAGE / LIMIT     MEM %     NET I/O           BLOCK I/O
a1b2c3d4e5f6   my-project-app-1   55.85%    255.2MiB / 7.782GiB   3.21%     1.2MB / 653kB     11.4MB / 0B
b2c3d4e5f6a1   my-project-db-1    2.12%     684.1MiB / 7.782GiB   8.57%     876kB / 432kB     156MB / 13.3GB

This table helps you find the container that is causing the problem.

Step 2: Understand the Numbers

Look at the columns to find any number that looks too high.

  • Problem: High CPU %
    • What it means: A process inside the container is working too hard. Maybe a script is in a loop that never ends. A CPU number that stays high (like over 50%) is a sign of a problem.
  • Problem: High MEM USAGE
    • What it means: The container is using a lot of computer memory (RAM). If this number keeps getting bigger and never goes down, your application probably has a "memory leak."
  • Problem: High BLOCK I/O
    • What it means: This shows how much the container is reading from or writing to the disk. The second number (writes) is very important. If a container is writing gigabytes (GB) of data, it is usually because of too much logging.

In our example table, my-project-app-1 has high CPU. And my-project-db-1 has extremely high disk writes (13.3GB!). We need to check these two containers.

Step 3: Look Inside the Container to Fix It

After you find the container with the problem, you need to look inside it. You can do this with the docker exec command.

# How to use it: docker exec -it <container_name_or_id> bash
docker exec -it my-project-db-1 bash

Now you are inside the container's terminal. Here is how to fix each type of problem.

Fixing High Disk Use (BLOCK I/O)

This is a very common problem. It is usually caused by too many log files.

  • How to check: Inside the container, you can use a command to find the biggest files. The du command is perfect for this.
    # Show the 10 biggest files and folders
    du -h . | sort -rh | head -n 10
  • A real example: In a MySQL container, you might find very large files named binlog in the /var/lib/mysql folder. This log saves every database change. You usually don't need this for local development.
  • How to fix it: You can turn this off in your docker-compose.yml file. Add command: --disable-log-bin to your MySQL service.

Fixing High CPU %

This means a process inside the container is out of control.

  • How to check: Inside the container, run the top command.
    top

    top shows you a list of all running processes, with the one using the most CPU at the top. This tells you which script or program is the problem.

  • How to fix it: You need to fix the bug in your application code. For example, maybe you have a loop that never stops.

Fixing High Memory (MEM USAGE)

This is usually caused by a memory leak in your application code.

  • How to check: The easiest way to check is to look at the container's logs for "Out of Memory" errors. Run this command from your main terminal (not inside the container).
    docker logs -f my-project-app-1
  • How to fix it: If you see memory errors, you will need to use a special tool to debug your application's code and find where the leak is.

Summary of the Steps

  1. Look: Run docker stats to see an overview of all containers.
  2. Find: Find the container with a high number for CPU, Memory, or Disk I/O.
  3. Go Inside: Use docker exec to open a terminal inside that container.
  4. Check: Use tools like top or du to find the exact process or file causing the issue.
  5. Fix: Fix the problem in your docker-compose.yml file or in your application code.
What I'm building

Delegate tasks. Get software.

Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.

Take a look at vroni.com

Subscribe to my newsletter

Get new posts when I publish them.

I respect your privacy. Unsubscribe at any time.

Leave a Reply

Your email address will not be published. Required fields are marked *