title: Super Slow Docker Build
body: <p>I think I'm going to go crazy.  I've searched all over and can't seem to find a working solution both here on Stack, GitHub and other far reaches of the interwebs.</p>
  
  <p>On this particular project, running <code>docker-compose build</code> is taking <strong><em>FOREVER</em></strong>.  It didn't use to be this way, and on other projects that use Docker, it's not an issue at all.  And by forever... I'm talking around 10-15 minute build times when it used to only take around 2 minutes tops.  I had two separate coworkers DL the <em>same repo</em> (one on Ubuntu 18, and the other on macOS 14.x).  When they ran the <code>build</code> command, the entire process took ~2 minutes.  Both of these people had never built this project before, so they were starting from complete scratch.</p>
  
  <p>I've uninstalled/reinstalled Docker, ran a complete <code>docker system prune -a</code>, connected via wifi, connected via Ethernet, tried a different wifi network, tweaked my compose file, tweaked my docker file -- nothing.  </p>
  
  <p>My machine is a 2018 MacBook Pro with a quad-core 2.7GHz i7, running macOS 10.14.6 with 16gb of installed RAM with Docker Desktop 2.1.0.5.</p>
  
  <p>I've allowed Docker Desktop to have up to 12gb or RAM.  During the build process, my machine cpu usage spikes on average from 110% up to 270% running the <code>com.docker.hyperkit</code> process.</p>
  
  <p>To be clear, it's hanging on the "Building php" (or "Building web") status message(s) before anything really even starts. After that, the actual build process runs smoothly and quick.</p>
  
  <p>Here is my <strong>docker-compose.yaml</strong> file:</p>
  
  <pre><code>version: '3.1'
  
  services:
    db:
      container_name: clientsname.db
      hostname: db
      image: mariadb:10.4.1-bionic
      volumes:
        - ./db-data:/var/lib/mysql:delegated
      ports:
        - 3307:3306
      environment:
        MYSQL_DATABASE: my_database
        MYSQL_USER: my_user
        MYSQL_PASSWORD: my_pass
        MYSQL_ROOT_PASSWORD: my_pass
  
    php:
      container_name: clientsname.php
      hostname: php
      build:
        dockerfile: php/php.dockerfile
        context: ./
      environment:
        XDEBUG_CONFIG: remote_host=${REMOTE_HOST}
  
      volumes:
        - ../web:/var/www/web
        - ../moodle:/var/www/moodle
        - ../moodledata:/var/www/moodledata
        - ./php/custom.ini:/usr/local/etc/php/conf.d/zzz-custom.ini
        - ./php/z-errors.ini:/usr/local/etc/php/conf.d/z-errors.ini:delegated
        - ./php/z-upload.ini:/usr/local/etc/php/conf.d/z-upload.ini:delegated
        - ./php/z-xdebug.ini:/usr/local/etc/php/conf.d/z-xdebug.ini:delegated
      depends_on:
        - db
  
    web:
      container_name: clientsname.web
      hostname: web
      build:
        dockerfile: nginx/nginx.dockerfile
        context: ./
      volumes:
        - ../web:/var/www/web
        - ../moodle:/var/www/moodle
        - ../moodledata:/var/www/moodledata
        - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
        - ./nginx/ssl:/etc/nginx/ssl
        - ./logs:/var/log/nginx
      ports:
        - 80:80
        - 443:443
      depends_on:
        - php
        - db
  
  </code></pre>
  
  <p>Here is the referenced <strong>php.dockerfile</strong> file:</p>
  
  <pre><code>FROM php:7.2.26-fpm
  LABEL maintainer="My Clients Name"
  
  # Environment variables
  ENV DEBIAN_FRONTEND=noninteractive
  ENV COMPOSER_ALLOW_SUPERUSER=1
  ENV COMPOSER_NO_INTERACTION=1
  ENV COMPOSER_HOME=/usr/local/share/composer
  
  # Working Directory
  WORKDIR /var/www/web
  WORKDIR /var/www/moodle
  WORKDIR /var/www/moodledata
  
  
  RUN rm /etc/apt/preferences.d/no-debian-php &amp;&amp; apt-get update &amp;&amp; apt-get install -y --no-install-recommends apt-utils \
          build-essential     \
          php-soap            \
          libzip-dev          \
          libmagickcore-dev   \
          libmagickwand-dev   \
          libmagic-dev        \
          libpng-dev          \
          libfreetype6-dev    \
          libjpeg62-turbo-dev \
          libmcrypt-dev       \
          libmemcached-dev    \
          zlib1g-dev          \
          nano                \
          sudo                \
          gnupg               \
          curl                \
          unzip &amp;&amp;            \
      docker-php-ext-install soap pdo_mysql mysqli &amp;&amp; \
      docker-php-ext-install -j$(nproc) gd iconv &amp;&amp; \
      docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ &amp;&amp; \
      pecl install zip-1.15.2 imagick memcached-3.0.4 xdebug &amp;&amp; \
      docker-php-ext-enable memcached imagick zip xdebug
  
  # Install Composer, Node, Gulp, and SASS
  RUN curl -s https://getcomposer.org/installer | php &amp;&amp; mv composer.phar /usr/local/bin/composer
  
  RUN curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - &amp;&amp; apt-get install -y nodejs &amp;&amp; npm install npm@latest -g &amp;&amp; npm install --global gulp-cli &amp;&amp; npm config set unsafe-perm=true
  
  
  # Export composer vendor path
  RUN echo "" &gt;&gt; ~/.bashrc &amp;&amp; echo 'export PATH="$HOME/.composer/vendor/bin:$PATH"' &gt;&gt; ~/.bashrc
  
  </code></pre>
  
  <p>And the referenced <strong>nginx.dockerfile</strong></p>
  
  <pre><code>FROM nginx:stable-alpine
  
  RUN apk add --update bash &amp;&amp; rm -rf /var/cache/apk/*
  
  WORKDIR /var/www/web
  
  </code></pre>
  
  <p>It's driving me batty... what in the bloody hell could I be doing wrong?  If there is anything I've left out that you'd all like to know, please let me know and I'll update the post.</p>
  
  <hr>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Thanks to @BMitch and you all who have commented thus far.  I took my entire /docker build directory and moved it into a test folder, and then created empty /web, /moodle, and /moodledata directories before running the <code>build</code> command.  It started to compile immediately.</p>
  
  <p>What's curious to me is that the other coworkers DL'd the same Git repo that I have and did not have any of the same issues.  Oooh... come to think of it... I bet I know what the issue is.</p>