title: Build of Dockerfile hangs or taking long?
body: <p>I have this Dockerfile:</p>
  
  <pre><code>FROM fedora:28
  
  # create new user
  RUN adduser --home /home/rpi-user rpi-user
  
  # install things needed for yocto
  RUN dnf -y install make wget bzip2 python unzip perl patch \
       diffstat git cpp gcc gcc-c++ glibc-devel texinfo chrpath \
       ccache perl-Data-Dumper perl-Text-ParseWords perl-Thread-Queue socat \
       findutils which SDL-devel xterm cpio file hostname rpcgen
  
  # run the commands that follow as rpi-user
  USER rpi-user
  
  # clone yocto/poky and raspberrypi layer
  RUN git clone git://git.yoctoproject.org/poky /home/rpi-user/poky
  RUN cd /home/rpi-user/poky; git clone https://github.com/agherzan/meta-raspberrypi.git
  
  # set up oe build environment and add meta-raspberrypi to bblayers.conf
  # modify machine name and add options to local.conf
  WORKDIR /home/rpi-user/poky
  ENV LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8
  COPY local.conf.append /tmp/
  RUN ls -l
  RUN . ./oe-init-build-env rpi-build; \
          cd conf; perl -0777 -pi -e 's/(BBLAYERS \?= "Provided more updates.[^"]*)"/\1\/home\/rpi-user\/poky\/meta-raspberrypi \\\n  "/g' bblayers.conf; \
          sed -i 's/\(MACHINE ??= \).*$/\1"raspberrypi3"/g' local.conf; \
          cat /tmp/local.conf.append &gt;&gt; local.conf; \
          cd ../; bitbake -DDDv rpi-basic-image;
  RUN echo "[!] Build complete."
  </code></pre>
  
  <p>Doing a <code>docker build -t bla/rpi .</code> results in my terminal hanging with (the last 6 lines):</p>
  
  <pre><code>NOTE: Running noexec task 3294 of 3294 (/home/rpi-user/poky/meta-raspberrypi/recipes-core/images/rpi-basic-image.bb:do_build)
  DEBUG: Teardown for bitbake-worker
  DEBUG: Teardown for bitbake-worker
  NOTE: Tasks Summary: Attempted 3294 tasks of which 5 didn't need to be rerun and all succeeded.
  
  Summary: There were 5 WARNING messages shown.
  </code></pre>
  
  <p>Running the exact same commands directly on a terminal on the same machine, I am able to build an image without a hang. Only when using docker (and only this specific Dockerfile) does my build hang. I am almost certain it is memory related. </p>
  
  <p>I usually use a script to remove any docker left overs which basically consists of a <code>docker rmi &lt;images&gt;</code>, <code>docker rm &lt;containers&gt;</code> and <code>docker system prune --volumes -f</code>, <a href="https://github.com/perplexabot/ckonduej/blob/master/docker_stuff/docker_scripts/remove_all_except.bash" rel="nofollow noreferrer">here</a> it is if interested. Using said script did not fix my issue (removing of containers, images and volumes did not fix the hang). I then removed <code>/var/lib/docker</code> and reset docker daemon, but still no luck. </p>
  
  <p>Any recommendations?</p>
  
  <h1>Update</h1>
  
  <p>Looking at <code>docker stats</code> while docker was building my Dockerfile, I saw that my cpu usage percentage was constantly over %100 (like in the thousands!). A <code>dmesg -w</code> shows messages like this:</p>
  
  <pre><code>[ 4409.558822] mce: CPU1: Core temperature above threshold, cpu clock throttled (total events = 3471)
  [ 4409.558823] mce: CPU7: Core temperature above threshold, cpu clock throttled (total events = 3471)
  [ 4409.558825] mce: CPU0: Package temperature above threshold, cpu clock throttled (total events = 4603)
  [ 4409.558826] mce: CPU6: Package temperature above threshold, cpu clock throttled (total events = 4603)
  </code></pre>
  
  <p>What is even more interesting is that with <code>docker stats</code> running, when the docker build hangs, the entry for that docker/image in <code>docker stats</code> goes away, and <code>dmesg</code> shows:</p>
  
  <pre><code>[ 4701.032315] docker0: port 1(veth0ef04d2) entered disabled state
  [ 4701.032481] veth2578e04: renamed from eth0
  [ 4701.130810] docker0: port 1(veth0ef04d2) entered disabled state
  [ 4701.135113] device veth0ef04d2 left promiscuous mode
  [ 4701.135137] docker0: port 1(veth0ef04d2) entered disabled state
  </code></pre>
  
  <p>Which I assume is what I should see upon the exiting of a docker build? Running a <code>ps aux | grep -i docker</code>, I still see the process running:</p>
  
  <pre><code>&lt;user&gt;    6281  0.9  0.1 1961860 27800 pts/1   Sl+  09:17   0:35 docker -D build -t bam/rpi .
  </code></pre>
  
  <p>So it seems docker thinks the build is done (<code>docker stats</code> removes the respective entry) but linux still sees the docker build running (<code>ps aux</code> still shows the process). What the? </p>
  
  <p>I am not able to get more "deets" from bitbake, unless there is a flag I am missing. <code>docker stats</code> did not show any memory issues as I was expecting.</p>
  
  <p>Wow, apparently a <code>docker ps -a</code> shows the container as exited also (in agreement with <code>docker stats</code>):</p>
  
  <pre><code>CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS               NAMES
  3ea12a369089        22be583f7349        "/bin/sh -c '. ./oe-…"   About an hour ago   Exited (0) 13 minutes ago                       nifty_gauss
  </code></pre>
  
  <p>I thought it couldn't get more interesting, but it did. In my <code>ps aux | grep -i docker</code>, I see an interesting process:</p>
  
  <pre><code>root      7775 19.2  1.1 2170612 181216 ?      Sl   10:13   4:04 docker-untar /var/lib/docker/overlay2/f3aade16d0d44ef61037ca5fc7ac0690f66b1894578141add2197fe7f8cdd402/diff
  </code></pre>
  
  <p>What is that? Is it untaring something? That can take a while. Maybe I should wait some more for this hang (I will). This process' <code>stat</code> column is constantly changing from <code>Rl</code> to <code>Sl</code> and back. Weird.</p>
  
  <p>So I waited. The docker-untar process is now gone, but the build is still hanging. Now when I do a <code>docker ps -a</code>,  i see this:</p>
  
  <pre><code>3ea12a369089        22be583f7349        "/bin/sh -c '. ./oe-…"   2 hours ago         Removal In Progress                           nifty_gauss
  </code></pre>
  
  <p>Interesting, will wait some more. </p>
  
  <p><strong>The waiting paid off</strong>. The docker image has, rather clumsily, successfully built. </p>
  
  <p><strong>Why is it taking so long using docker (about x4 longer than running on
  the same machine without docker) to build an arm based binary?</strong></p>