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, 2019 in Puppet by Sam
• 6,260 points
2,086 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, 2019 by Sirajul
• 59,230 points

Related Questions In Puppet

0 votes
1 answer

Can I launch a Puppet Server using the puppet/puppetserver-standalone docker image?

In order to launch a Puppet Server ...READ MORE

answered Aug 23, 2019 in Puppet by Sirajul
• 59,230 points
1,216 views
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, 2019 in Puppet by Jason
1,516 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, 2019 in Puppet by Sam
• 6,260 points
1,027 views
0 votes
1 answer

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

docker_volume { 'nfs-volume': ensure => ...READ MORE

answered Aug 13, 2019 in Puppet by Sirajul
• 59,230 points
744 views
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, 2019 in Puppet by Sirajul
• 59,230 points
926 views
+2 votes
1 answer
+2 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
• 58,020 points
2,714 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP