Quickly build a Debian package with Docker

on 2015-03-03

Build from bootstrap packages is important, you sometimes forget some packages on the Build-Depends, or you found some FTBFS that will not happen with your setup.

I've been using sbuild for that purpose in the past.

I use the Docker registry with debian:stable base image.

FROM debian:stable

ENV DEBIAN_FRONTEND noninteractive
ENV DEBIAN_PRIORITY critical
ENV DEBCONF_NOWARNINGS yes

RUN apt-get update && apt-get -y upgrade
RUN apt-get -y --no-install-recommends install devscripts equivs

WORKDIR /root
ADD . /root
RUN mk-build-deps -t "apt-get -y --no-install-recommends" -i "debian/control"
RUN dpkg-buildpackage -b
RUN debi

VOLUME /output
CMD cp *.deb ../*.deb /output

This is a generic Dockerfile. I'm installing required scripts and tools to build a package.

Install build dependencies with mk-build-deps that create a fake package for that. You can use apt-get build-dep if the package is already in the Debian repository and have deb-src on your list.

I'm finally building a binary package, and install it on the container, to see if everything is fine.

To build the container and the package:

docker build -t debian_package_build .
docker run --rm -v /tmp:/output debian_package_build

The package will be present in /tmp on your host.