Demonstrate running facter from inside the container:
docker run puppet/facter
Demonstrate running Puppet from the container:
docker run puppet/puppet-agent --help
Run a simple inline apply, and show it changed the container. Not useful in itself but demonstrates Puppet is present.
docker run --name apply-test puppet/puppet-agent apply -e 'file { "/tmp/adhoc": content => "Written from puppet on $hostname\n" }'
docker diff apply-test
Running a full Puppet stack using Docker Compose: https://github.com/puppetlabs/puppet-in-docker-examples/tree/master/compose
Running the same on Hyper_: https://github.com/puppetlabs/puppet-in-docker-examples/tree/master/hyper_
Running the same on Google Container Engine (GKE): https://github.com/puppetlabs/puppet-in-docker-examples/tree/master/kubernetes
As an example of running Puppet on a container-centric OS we'll look at running on VMware Phonton OS: https://github.com/puppetlabs/puppet-in-docker-examples/tree/master/photonos
docker build
puppet docker build
puppet docker dockerfile
Nginx example: https://github.com/puppetlabs/puppetlabs-image_build/tree/master/examples/nginx
Multi-image build example: https://github.com/puppetlabs/puppetlabs-image_build/tree/master/examples/multi
Given the following Dockerfile:
FROM ubuntu:16.04
MAINTAINER Gareth Rushgrove "gareth@puppet.com"
ENV PUPPET_AGENT_VERSION="1.5.0" \
R10K_VERSION="2.2.2" \
UBUNTU_CODENAME="xenial"
PUPPET_INSTALL
PUPPET_COPY_PUPPETFILE
PUPPET_COPY_MANIFESTS
PUPPET_RUN
EXPOSE 80
CMD ["nginx"]
Pass it through the pre-processor to get a working Dockerfile.
cat Dockerfile | ./dockerfilepp-puppet
See https://github.com/garethr/dockerfilepp-puppet for the download and more examples.
Run an inventory on an image which doesn't contain Puppet.
docker run --name puppet-inventory puppet/puppet-inventory
docker run --rm -it --volumes-from=puppet-inventory centos /opt/puppetlabs/bin/puppet inventory
Retrieve the underlying operating system in the container:
docker run puppet/puppet-inventory | jq '.facts.operatingsystem'
List all the users in the container:
docker run puppet/puppet-inventory | jq '.resources' | jq 'map(select(.resource == "user"))'
docker run puppet/puppet-inventory | jq '.resources' | jq 'map(select(.resource == "user"))' | jq '.[] .title'
List all resources with ssl
in the title:
docker run puppet/puppet-inventory | jq '.resources' | jq 'map(select(.title | contains("ssl")))'
The version of OpenSSL installed:
docker run puppet/puppet-inventory | jq '.resources[] | select(.title == "openssl") .versions[0]'
Count the number of package resources:
docker run puppet/nginx cat /inventory.json | jq -c '.resources[] | select(.resource=="package")' | jq -s length