docker/docker — pull request #9630 by ztombol (2014-12-12 15:15:25+00:00)
Title: Fix #9462

***Note:*** *credit goes to @jprjr and @k2s who [tracked down and fixed this bug][jprjr-gh-issue] and @nasicus who [first reported it][nasicus-forum-report]. I verified that jprjr's fix works and since he didn't submit a patch to upstream for 10 days, I prepared this patch.*

# Overview

`gpg-agent` prevents `arch-chroot` to unmount `/dev`, and ultimately to mount it again when run next.

# Details

`pacman-key --init` starts `gpg-agent` in the background that keeps `/dev/{null,random,urandom}` open. This prevents `arch-chroot` to unmount `/dev` from the chroot on exit (*"umount: target is busy"* messages). The script actually fails on the second invocation of `arch-chroot` when it fails to mount `/dev` because it stayed mounted after the first `arch-chroot` exited. This causes the *"ERROR: failed to setup API filesystems in chroot"* error and `mkimage-arch.sh` to exit.

The solution is to kill `gpg-agent` before exiting the chroot.

[jprjr-gh-issue]: https://github.com/jprjr/docker-archlinux/issues/1
[nasicus-forum-report]: https://forums.docker.com/t/creating-base-image-from-archlinux-script-not-working/415