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