Creating Dev and Production Images with Packer in Parallel

30 minutes
  • 3 Learning Objectives

About this Hands-on Lab

One of the primary benefits of using Packer to build your images is it can create multiple images in parallel, allowing you to use the same baseline to provision things such as both development and production images. In this lab, we’ll take a Packer template set to create a web instance and add the ability to provision a Docker image.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Add the Docker Builder
  1. Open the provided packer.json file.
  2. Add the Docker builder to specification.
  3. Save and exit.
Refactor the Provisioners
  1. Since we start Apache in the builder section of the Docker build, we need to remove that part of the provided script, then add it again so it runs only on the Amazon EBS builder. Let’s first open the script.
  2. Remove the systemctl commands.
  3. Add them as an inline shell provisioner, solely for the AWS builder.
Test the Build
  1. Update the AWS access key and subnet information.
  2. Save and exit the file.
  3. Test the build.

Additional Resources

You have finished setting up the Packer provisioning for your company's website instance but want to provide an additional Docker image for the web developers to use. The current template uses Ubuntu 18.04 as the base image and will need to set the following Docker instruction:

  • ENTRYPOINT ["apache2ctl", "-D", "FOREGROUND"]

Take the provided packer.json template and refactor it (and related scripts) to also provision a Docker image.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?