Docker build is slow (or docker-compose build is slow)

Today, 27th January 2023, Ukraine is still bravely fighting for democratic values, human rights and peace in whole world. Russians ruthlessly kill all civilians in Ukraine including childs and destroy their cities. We are uniting against Putinโ€™s invasion and violence, in support of the people in Ukraine. You can help by donating to Ukrainian's army.

All root folder (build context) sent to docker daemon (even files that not ADDed yet), so the reason of the slow build is the large amount of files or files data size

  1. add .git to .dockerignore or folder of your VCS, it has pretty much small files
  2. Use ncdu in your dir to find large dirs
apt-get install ncdu
cd <project root where Dockerfile is>

Then you will find large folders/files that you will need to add to .dockerignore

E.g. to remove all node_modules folders (from root and subfolders)


But know, that if you will then try ADD ignored dir, you may have an error:

ERROR: Service 'web' failed to build: ADD failed: stat /mnt/sda1/var/lib/docker/tmp/docker-builder569
314723/media: no such file or directory

Not solved yet?

Some folks say that named pipes may cause an issue, so if nothing above helped try:

find . -type p -delete
docker-compose build
Ivan Borshchov profile picture
Nov 16, 2017
by Ivan Borshchov
Did it help you?
Yes !

Best related