At some point, a newer version of a package is required …

Possible ways how to build a package

  • The poor mans version is to pull the source, install build-dependencies and compilers and build the package on the target machine. Afterwards, the build dependencies / compilers are uninstalled.
  • The clean and sophisticated way is using chroots, e.g. by using pbuilder. This requires a maintained pbuilder installation, however.
  • Here, I’ll show how docker can be (ab)used to quickly obtain a package. This even works on MacOSX / Windows using boot2docker.

Docker Example:

My example here is building lxc for debian wheezy. Wheezy itself has 0.8.x in its repositories, but 1.0.6 from the jessie repos is desired.

Commented Dockerfile:

# We use the debian wheezy base image
FROM debian:wheezy

# Install dpkg-dev from wheezy
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y dpkg-dev; \

# Patch sources list to contain wheezy-backports and jessie
    echo "deb http://ftp.de.debian.org/debian/ jessie main non-free contrib" >> /etc/apt/sources.list.d/jessie.list; \
    echo "deb-src http://ftp.de.debian.org/debian/ jessie main non-free contrib" >> /etc/apt/sources.list.d/jessie.list: \
    echo "deb http://ftp.de.debian.org/debian/ wheezy-backports main" >> /etc/apt/sources.list: \
    apt-get update; \

WORKDIR /root

# Now we get the source
RUN apt-get source lxc

# Remove jessie sources.list and install build dependencies
RUN rm /etc/apt/sources.list.d/jessie.list && apt-get update
RUN apt-get install -y build-essential fakeroot dpkg-dev dh-autoreconf doxygen docbook2x graphviz libapparmor-dev liblua5.2-dev libseccomp-dev libselinux-dev pkg-config python3-dev dh-systemd libcap-dev

# Switch to lxc directory and build the package
RUN cd lxc-1.0.6; dpkg-buildpackage -b

# Create output volume, running the container just copies the 
VOLUME /output
CMD cp *.deb /output

Building the lxc package

docker build -t lxc-build .
docker run --rm /tmp:/output lxc-build

Complete Dockerfile:

FROM debian:wheezy

RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y dpkg-dev; \
    echo "deb http://ftp.de.debian.org/debian/ jessie main non-free contrib" >> /etc/apt/sources.list.d/jessie.list; \
    echo "deb-src http://ftp.de.debian.org/debian/ jessie main non-free contrib" >> /etc/apt/sources.list.d/jessie.list: \
    echo "deb http://ftp.de.debian.org/debian/ wheezy-backports main" >> /etc/apt/sources.list: \
    apt-get update; \

WORKDIR /root
RUN apt-get source lxc
RUN rm /etc/apt/sources.list.d/jessie.list && apt-get update
RUN apt-get install -y build-essential fakeroot dpkg-dev dh-autoreconf doxygen docbook2x graphviz libapparmor-dev liblua5.2-dev libseccomp-dev libselinux-dev pkg-config python3-dev dh-systemd libcap-dev
RUN cd lxc-1.0.6; dpkg-buildpackage -b
VOLUME /output
CMD cp *.deb /output