Tutorial on how to use Docker to build Debian packages
Go to file
Tero Saarni 31f4ec4c4a Added link to container-deb-builder 2023-08-30 17:21:36 +03:00
Dockerfile-Debian-bookworm-12 Added new distro releases 2023-08-19 11:21:35 +03:00
Dockerfile-Debian-bullseye-11 feat(debian): add dockerfiles for deb9,deb10,deb11 2021-10-01 17:34:51 +02:00
Dockerfile-Debian-buster-10 feat(debian): add dockerfiles for deb9,deb10,deb11 2021-10-01 17:34:51 +02:00
Dockerfile-Debian-sid-unstable Added Dockerfile for debian unstable (sid) (#7) 2022-12-29 13:28:51 +02:00
Dockerfile-Debian-stretch-9 feat(debian): add dockerfiles for deb9,deb10,deb11 2021-10-01 17:34:51 +02:00
Dockerfile-ubuntu-17.04 initial commit 2017-04-20 06:27:24 +03:00
Dockerfile-ubuntu-18.04 added ubuntu 18.04, allow running build script from elsewhere than cwd 2018-07-14 00:30:09 +03:00
Dockerfile-ubuntu-19.10 Add Dockerfile for Ubuntu 19.10 2020-01-29 17:20:18 +01:00
Dockerfile-ubuntu-20.04 Add Dockerfile for Ubuntu 20.04 2020-09-14 10:31:42 +03:00
Dockerfile-ubuntu-22.04 Added new distro releases 2023-08-19 11:21:35 +03:00
LICENSE Initial commit 2017-04-19 17:39:52 +03:00
README.md Added link to container-deb-builder 2023-08-30 17:21:36 +03:00
build Disable targeted volumes if any (#6) 2022-10-19 18:53:40 +03:00
build-helper.sh buildinfo and changes are also saved (#4) 2021-10-31 08:27:37 +02:00

README.md

Creating Debian packages in Docker container

Overview

Docker can be used to set up a clean build environment for Debian packaging. This tutorial shows how to create a container with required build tools and how to use it to build packages.

For more complete solution with many improvements see container-deb-builder.

Create build environment

Start by building a container that will act as package build environment:

docker build -t docker-deb-builder:17.04 -f Dockerfile-ubuntu-17.04 .

In this example the target is Ubuntu 17.04 but you can create and modify Dockerfile-nnn to match your target environment.

Building packages

First download or git clone the source code of the package you are building:

git clone ... ~/my-package-source

The source code should contain subdirectory called debian with at least a minimum set of packaging files: control, copyright, changelog and rules.

Clone the docker-deb-builder (the repository you are reading now) and run the build script to see usage:

$ ./build
usage: build [options...] SOURCEDIR
Options:
  -i IMAGE  Name of the docker image (including tag) to use as package build environment.
  -o DIR    Destination directory to store packages to.
  -d DIR    Directory that contains other deb packages that need to be installed before build.

To build Debian packages run following commands:

# create destination directory to store the build results
mkdir output

# build package from source directory
./build -i docker-deb-builder:17.04 -o output ~/my-package-source

After successful build you will find the .deb files in output directory.

Sometimes build might require dependencies that cannot be installed with apt-get build-dep. You can install them into the build environment by passing option -d DIR where DIR is a directory with *.deb files in it.

./build -i docker-deb-builder:17.04 -o output -d dependencies ~/my-package-source

Integrating with CI

In this tutorial all package-specific build dependencies are installed from scratch each time build is executed in the container. The benefit is that the container is generic and reusable for building any package but the installation of build-time dependencies can add up to considerable overhead, both in time and bandwidth. This overhead may not be acceptable when building packages as part of continuous integration pipeline. One possible solution to reduce overhead is to install package-specific build dependencies into build environment container.