Building dynamic containers
Although Dockerfiles are a fairly powerful and flexible way of building containers, they are only static text files, and very often you will need to pass information into the container to tell it what to do. We might call such containers, whose configuration is flexible and based on data available at build time, dynamic containers.
Configuring containers with templates
One way to configure containers dynamically is to use Puppet to manage the Dockerfile as an EPP template (see Chapter 9, Managing files with templates), and interpolate the required data (which could come from Hiera, Facter, or directly from Puppet code).
Let's upgrade our previous Hello, world
example to have Nginx serve any arbitrary text string supplied by Puppet at build time.
Here's the manifest to generate the Dockerfile from a template (docker_template.pp
):
file { '/tmp/Dockerfile.nginx': content => epp('/vagrant/examples/Dockerfile.nginx.epp', { 'message' => 'Containers rule...