- A Cloud Guru
Building a Docker Image with Packer
Packer allows us to create machine images using a number of builders — including Docker images! Built _without_ the use of a Dockerfile, using Packer with Docker requires the use of simple scripts and some metadata changes to get everything up and running. In this lab, we'll do just that by creating a Docker image to deploy a Node.js application.
Table of Contents
Refactor the Dockerfile
Packer provisions Docker images using the same provisioners as any other image. That said, not all steps in the build will work one-to-one.
Additionally, the follow Dockerfile instructions can be provided as metadata in the build itself:
These will run as intended with a container launched from the image.
We'll refactor our template to use the
shellprovisioners to create our script.
Write the Docker Builder Block
Write the builder block for the Docker builder, and add the relevant post-processors.
Test the Build
- Validate the template.
- Test the build.
What's a lab?
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.