Puppet+Docker: pull an image and launch a container

0 votes
I am experimenting on integrating a containerization tool (docker) and config management tool (puppet). How can i pull an image from the repository and launch a container using puppet code?
Aug 13 in Puppet by Sam
• 4,330 points
146 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes
  • I hope you have docker module from puppet forge. If not do it.

$ sudo puppet module install garethr-docker
Notice: Preparing to install into /etc/puppet/modules ...
Notice: Downloading from https://forgeapi.puppetlabs.com ...
Notice: Installing -- do not interrupt ...
/etc/puppet/modules
|--- garethr-docker (v4.1.1)
  |-- puppetlabs-apt (v2.1.1)
  |-- puppetlabs-stdlib (v4.9.0)
  |-- stahnma-epel (v1.1.1)
  • Here's a docker_example.pp

  • The /etc/puppet/manifests/docker_example.pp should look something like:

include 'docker'
docker::image { 'ubuntu':
   image_tag => 'trusty',
}
  • The module includes a single class:

include 'docker'
  • By default, this sets up the docker hosted repository if necessary for our OS, and installs the docker package and on Ubuntu, any required Kernel extensions.

docker::image { 'ubuntu':
  image_tag => 'trusty'
}
  • The image tags is equivalent to running docker pull -t="trusty" ubuntu. 

  • Note that the image will only install if an image of that name does not already exist.

  • Let's apply the puppet manifest (/etc/puppet/manifests/docker_example.pp) in order to get docker installed on our puppet master:

$ sudo puppet apply site.pp
...
Notice: Finished catalog run in 46.40 seconds
  • check if docker has been properly installed:

$ sudo docker version
Client version: 1.7.1
Client API version: 1.19
Go version (client): go1.4.2
Git commit (client): 786b29d
OS/Arch (client): linux/amd64
Server version: 1.7.1
Server API version: 1.19
Go version (server): go1.4.2
Git commit (server): 786b29d
OS/Arch (server): linux/amd64
  • Also, check that there is no running docker container:

$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
  • Check the installation of the ubuntu docker image:

$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
ubuntu              trusty              91e54dfb1179        3 weeks ago         188.4 MB
  • Now we have an image to work with. We can launch containers like this:

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

 The above code snippet is equivalent to running the following:

docker run -d base /bin/sh -c "while true; do echo hello world; sleep 1; done"

This will launch a Docker container.

answered Aug 13 by Sirajul
• 41,000 points

Related Questions In Puppet

0 votes
1 answer
0 votes
1 answer

Is it possible to install puppet agent in a docker container on linux?

Hey @Janice, this is pretty simple. Create ...READ MORE

answered Mar 12 in Puppet by Jason
207 views
0 votes
0 answers

Puppet+Docker: Rebuild an image with respect to changes in dockerfile

I am building a docker image via ...READ MORE

Aug 13 in Puppet by Sam
• 4,330 points
33 views
0 votes
1 answer
0 votes
1 answer

Puppet+Docker: How do i configure my docker container to use a NFS volume through a Hiera config file?

If using Hiera, configure the docker::volumes class in the ...READ MORE

answered Aug 14 in Puppet by Sirajul
• 41,000 points
40 views
0 votes
1 answer
0 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 57,300 points
270 views