Docker Community Forums

Share and learn in the Docker community.

Can we build custom Docker images with Puppet?


(LuciferDude) #1

Is it possible to build custom docker images with Puppet?. I was successfully able to manage containers that were downloaded from docker hub through puppet but when i try to build my own image first, nothing happens in Puppet.

include 'docker'

    docker::image { 'centos':
    ensure      => 'present',
    }

    file { '/tmp/DockerFilePuppet':
    ensure  => file,
    content => template('/etc/puppet/templates/docker/DockerFilePuppet.erb'),
    require => Package['docker'],
    }

    file { '/tmp/puppet.conf':
    ensure  => file,
    content => template('/etc/puppet/templates/docker/puppetconfig.erb'),
    require => Package['docker'],
    }

    docker::image { 'puppetimage':
    ensure        => 'present',
    docker_file   => '/tmp/DockerFilePuppet',
    }


     docker::run { 'PuppetContainer':
     image   => 'puppetimage',
     hostname => 'my.domain.net',
     require => Docker::Image['puppetimage'],

    }

(Johnbritt429) #2

At PuppetConf 2016, we shipped the first release of the image_build module. As its name suggests, this module provides a simple way of taking Puppet code and building images, including Docker images. The module is available for everyone today, and the source code is up on GitHub.

Now you can use Puppet to solve two problems with large Docker workflows:

You have a Puppet code base, and you’re moving some of your services into containers. By sharing the same code across your infrastructure, regardless of whether or not it uses containers, you can cut down on duplication of effort, and take advantage of work you’ve already done.
You’re building many images, but scaling Dockerfile involves either a complex hierarchy of images or copying and pasting snippets between many individual Dockerfiles. The image_build Puppet module lets you share common functionality using the familiar Puppet modules mechanism, and Puppet itself provides a rich domain-specific language for declarative composition of images.

Source: https://puppet.com/blog/building-docker-images-puppet