The build fails with a dpkg lock error

The image build fails with a dpkg lock error because cloud-init was still running its first-boot package steps.

Condition

The build fails with Could not get lock /var/lib/dpkg/lock-frontend.

Cause

cloud-init was still running its first-boot package steps.

Remedy

Run cloud-init status --wait before the build steps.