Fix Insane Disk I/O in Laravel Sail: Disable MySQL Binary Logs
Is your Docker-based development environment sluggish? Do your fans spin up for no reason? If you run docker stats, do you see…
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.
docker statsThe 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.
Look at the columns to find any number that looks too high.
CPU %
MEM USAGE
BLOCK I/O
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.
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.
This is a very common problem. It is usually caused by too many log files.
du command is perfect for this.
# Show the 10 biggest files and folders
du -h . | sort -rh | head -n 10
binlog in the /var/lib/mysql folder. This log saves every database change. You usually don't need this for local development.docker-compose.yml file. Add command: --disable-log-bin to your MySQL service.This means a process inside the container is out of control.
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.
This is usually caused by a memory leak in your application code.
docker logs -f my-project-app-1
docker stats to see an overview of all containers.docker exec to open a terminal inside that container.top or du to find the exact process or file causing the issue.docker-compose.yml file or in your application code.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