BT

New Early adopter or innovator? InfoQ has been working on some new features for you. Learn more

Puppet Releases Docker-Focused Features in Project Blueshift

| by John Okoro Follow 0 Followers on Jul 20, 2016. Estimated reading time: 3 minutes |

In context of its Project Blueshift, Puppet has added a new set of Docker images for running Puppet software released to Docker Hub.

Examples of these new Docker images include a Puppet Server image that allows for running Puppet Server (which can stand alone or run with accompanying PuppetDB) and a PuppetDB image that includes the accompanying PostgreSQL image. There are also two agent images, one based on the Ubuntu Xenial Puppet Agent package and the other based on the slimmed down Alpine release.

Blueshift is a demonstration of solutions to the problem of managing heterogeneous software, using Puppet as the unified way of managing the new software stack. Blueshift includes information from the Puppet community on how to integrate with technologies like Consul, CoreOS and Mesos. Blueshift also includes internal engineering from Puppet.

Puppet also provides examples of how to use Puppet in Docker. There are currently examples showing how to use Puppet in Docker on VMware Photon OS, Red Hat CentOS Atomic, and on CoreOS. There are also examples of how to stand up a Puppet infrastructure using Docker Compose.

In one Project Blueshift example, Gareth Rushgrove demonstrates how to manage Docker containers using Puppet. The Puppet Docker module was first released around the initial release of Docker, and has been a community effort since then.

The first step is to install the Puppet Docker example module:

# puppet module install garethr-docker

At its simplest, the Docker module allows you to install Docker with one line in your manifest.

include 'docker'

It is possible to declare as many images as desired in your manifest. In this example, an Ubuntu image is used.

docker::image { ‘ubuntu':
  image => 'trusty',
}

These simple Docker containers can now easily be applied using Puppet. Docker version will show that Docker is installed, along with details of the version.

# puppet apply /vagrant/docker_example.pp

# docker version
Client version: 1.5.0
Client API version: 1.17
Go version (client): go1.4.1
Git commit (client):a8a31ef
OS/Arch (client): linux/amd64
Server version: 1.5.0
Server API version: 1.17
Go version (server): go1.4.1
Git commit (server): a8a31ef
#

Docker ps will show that there is nothing currently running.

# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
#

Docker images will show that the Docker image has been created.

# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
Ubuntu trusty d0955f21bf24 3 weeks ago 188.3 MB
Ubuntu trusty-20150320 d0955f21bf24 3 weeks ago 188.3 MB
Ubuntu latest d0955f21bf24 3 weeks ago 188.3 MB
Ubuntu 14.04 d0955f21bf24 3 weeks ago 188.3 MB
Ubuntu 14.04.2 d0955f21bf24 3 weeks ago 188.3 MB #

The Docker module supports running and managing individual Docker containers. The containers can run under the host init system (like systemd or sysvinit) or using Docker’s built-in process manager. Next two simple Docker run resources are added.

docker::run { 'helloworld':
  image   => 'ubuntu',
  command => '/bin/sh -c "while true; do echo hello world; sleep 1; done"',
}

docker::run { 'goodbyecruelworld':
  image   => 'ubuntu',
  command => '/bin/sh -c "while true; do echo goodbye cruel world; sleep 1; done"',
}

Using puppet apply, we can quickly apply the updates to the two services that will run in the Docker containers. Docker ps will now show that there are currently two simple services running.

# Puppet apply /vagrant/docker_example.pp
Notice: Compiled catalog for localhost in environment production in 0.93 seconds
Notice: /Stage[main]/Main/Docker::Run[helloworld]/File[/etc/init.d/docker-helloworld]/ensure: created
Notice: /Stage[main]/Main/Docker::Run[helloworld]/Service[docker-helloworld]/ensure: ensure changed ‘stopped’to ‘running’
Notice: /Stage[main]/Main/Docker::Run[goodbyecruelworld]/File[/etc/init.d/docker-goodbyecruelworld]/ensure: created 
Notice: /Stage[main]/Main/Docker::Run[goodbyecruelworld]/Service[docker-goodbyecruelworld]/ensure: ensure changed ‘stopped’ to ‘running’
Notice: Finished catalog run in 1.11 seconds

# docker ps 
CONTAINER ID   IMAGE	  COMMAND               CREATED         STATUS         PORTS  NAMES
27b9ca786f9b   ubuntu:14.04 “/bin/sh -c ‘while t  18 seconds ago  Up 17 seconds         jolly_wright
4ec0c0225714   ubuntu:14.04 “/bin/sh -c ‘while t  18 seconds ago  Up 17 seconds         focused_wright
#

Attaching to one of the services using docker attach and the container ID will show the service executing in docker.

# docker attach 27b9ca786f9b
goodbye cruel world
goodbye cruel world
goodbye cruel world 
^C#
#
# docker attach 4ec0c0225714
hello world
hello world
hello world 
^C#
# 

The Docker module also supports actions like mounting volumes, setting environment variables, running privileged containers, and exposing ports. Puppet can also execute commands within the context of running containers using the docker exec feature.

docker::exec { 'helloworld-uptime':
  detach => true,
  container => 'helloworld',
  command => 'uptime',
  tty => true,
}

 

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT