Building a Docker Image using Packer and Jenkins

1 hour
  • 3 Learning Objectives

About this Hands-on Lab

In this hands-on lab, you will be taking on the role of a DevOps engineer who manages a Packer file that is used to create a Docker image for one of the team’s applications. You have created a new Packer file and committed it to GitHub. Now you want to automate the build process. The team has a Jenkins server that is used for running tests against the code. You have decided to create a Jenkins job to help manage the build process.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Open port 8080 on firewalld.
  1. Open the firewall
    sudo firewall-cmd --zone=public --permanent --add-port=8080/tcp
    sudo firewall-cmd --reload
  2. Check the firewall.
    sudo firewall-cmd --zone=public --permanent --list-ports
Create the Packer build job.
Run the build job.

Additional Resources

  1. Jenkins has already been installed for you. Open port 8080 by executing the following commands:
    firewall-cmd --zone=public --permanent --add-port=8080/tcp
    firewall-cmd --reload
  2. Make sure that port 8080 is listed.
    firewall-cmd --zone=public --permanent --list-ports
  3. If the output is 8080/tcp, your environment has been properly configured.
  4. Log in to the Jenkins server at http://<IP_ADDRESS>:8080 to complete the setup.
  5. Expand the contents of the password secrets file to get the admin password for Jenkins.
    cat /var/lib/jenkins/secrets/initialAdminPassword
  6. Install the suggested default plugins.
  7. Create a new Freestyle project called BuildAppImage.
  8. Use the following GitHub repository:
  9. Create a string parameter called repo_name. Set the default value to la/express.
  10. Add an Execute shell build step.
    • This build step will be used to execute a Packer build.
    • The build will include two variables.
    • You will need to supply the full path to Packer.
    • The first variable will be repository, which will use the repo_name parameter.
    • The second variable will be a tag that uses the job build number.
  11. Save the job and test it by executing the job.
  12. Verify that the image has been created.

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?