Creating abstracted Dockerfile is something I really wish existed. Every time,
I write a
Dockerfile for a specific base image I must specify the correct
package manager command. I must call
yum or any other
call for the package manager. This is unfortunately, not very reusable.
I am comparing this to many years of experience with
salt-stack which includes
a great wrapper around many common Linux package managers. This spares the
details of distinguishing between
dnf, you just
pkg.install and you get your packages installed.
Here is a simple
M4 schema how to achieve this abstraction. A better
solution will probably involve Jinja2 templates ...
This can spare you the need to remember which package manager you need to use
in which Docker image. Here is a very quick intro, how to this.
First create an
$ cat Dockerfile.in FROM ifdef(`ALPINE', alpine, ubuntu) MAINTAINER Oz N Tiram <email@example.com> RUN ifdef(`ALPINE', apk add --update --no-cache, apt-get update && apt-get install -y) curl tar xz bash
Now, create a simple
$ cat Makefile ALPINE ?= ifdef ALPINE USE_ALPINE := -DALPINE endif dockerfile: @m4 $(USE_ALPINE) Dockerfile.in
Now you can create
Dockerfile for your image from Ubuntu with:
$ make > Dockerfile
Or you can create a
Dockerfile based on Alpine Linux:
$ make ALPINE=1 > Dockerfile