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.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- 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:
USER
ENTRYPOINT
WORKDIR
EXPOSE
CMD
These will run as intended with a container launched from the image.
We’ll refactor our template to use the
file
andshell
provisioners 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.