Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Images Are Being Slow to Build on Windows/MVC Core

I have a MVC Core 2.2 with multiple projects in docker containers. When I run it, it takes approximately 4 minutes to build the images and fire up the containers. I am using docker-compose.

This seems slow, given that this is small development and I have a decent computer. It seems that the resources are not being used, because processor is under 8% during image build, ram doesn't budge, disk almost at 0%. GPU 0%. I can see internet spiking for a few seconds while Microsoft image is downloaded, but that's it. I have given docker the following resources:

Cores: 8
RAM: 8GB
SWAP: 3gb
Disk Image Size: 64GB (30.5 GB used)

Any ideas how these hardware resources can be used to make builds faster?

like image 948
mgPePe Avatar asked Jan 29 '20 09:01

mgPePe


2 Answers

check if there are too many files in the build directory , if there is dcoker need to send all the files to the daemon which need also time to finish......

you can ignore the unwanted files using .dockerignore

Before the docker CLI sends the context to the docker daemon, it looks for a file named .dockerignore in the root directory of the context. If this file exists, the CLI modifies the context to exclude files and directories that match patterns in it. This helps to avoid unnecessarily sending large or sensitive files and directories to the daemon and potentially adding them to images using ADD or COPY.

like image 128
LinPy Avatar answered Oct 19 '22 05:10

LinPy


It seems to be a general issue with Docker on Windows 10 because I found several threads on the web speaking about this issue and it seems generally not related to hardware resource assigned to Docker.

So I've done some tries on my Windows 10 virtual instance and noticed a similar behaviour running some Linux-based containers using an example docker-compose.

Here I report steps, from all of ones I found during my searches, that really seemed to speed up the operations during my tests:

  1. Add development ( e.g. git repos ) and docker image directories on:

    • Windows Defender Exclusion list ( https://support.microsoft.com/en-us/help/4028485/windows-10-add-an-exclusion-to-windows-defender-antivirus )

      NOTE: Here first just try to disable Windows Defender to see if it help

    • Windows Indexing exclusion list ( Control Panel -> Indexing Options )

  2. Flush dns executing the following command:

    ipconfig /flushdns
    
  3. Try to change DNS to for example Google one ( 8.8.8.8 - 8.8.4.4 ) or Cloud Fare one ( 1.1.1.1 - 1.0.0.1 ) ( Here, as I already had the Google DNS, I tried in the opposite way setting a slower DNS and really operations became a little bit slower )

  4. Add exception if any other antivirus is installed ( also here first try disabling them to see if this can help )

  5. Remove all IPV6 support and NetBIOS from all network interfaces

NOTE: Someone advice to uninstall Docker and install after these applies but I didn't test because I've started from a fresh Windows 10 installation.

Hope these can help also on your environment!

Best References I found:

  • https://github.com/docker/for-win/issues/1936
  • https://forums.docker.com/t/docker-for-windows-very-slow-networking-host-directory-as-a-volume/25758
like image 33
gregorycallea Avatar answered Oct 19 '22 06:10

gregorycallea