github twitter linkedin email
Building containers with Docker Vs Packer
Jul 6, 2017
3 minutes read

Containerisation and micro-services are the current big things in DevOps. There are so many tools that allow you to build your containers, deploy them to the cloud and have them run your code. The way people work is changing, new technologies are constantly being created; everyday can be a new day with newer and better solutions discovered to problems we are facing in this present day. I will be looking at two different methods to simply generate a container and run a simple ‘Hello World!’ Java Spring Boot web application. The code for the whole project can be found here though I will include snippets of code below.


The simplest method one can start creating containers with is using tools part of the Docker eco-system. You can use docker-build to create the image from a Dockerfile and then use docker-compose to spin up a containers with said image. Here is a basic example of a Dockerfile: As someone has already created an image specific for Java I can simply import it and not have to worry about setting up the image myself. The image bellow shows some output during the build phase, after that docker-compose will deploy a container for us and sort out the networking etc.

Building with Docker


Another option is Packer. Packer is a tool created by HashiCorp, in my opinion one of the leaders in driving the evolution of DevOps. This tool is like docker-build but on steroids, Packer is not just for Docker but it can be used with a number of virtualisation solutions. Below is an example config file for Packer: Packer is split into three main sections: builders, provisioners and post-processors. Packer can build images for a number of platforms:

  • Alicloud ECS
  • Amazon EC2
  • Azure
  • CloudStack
  • DigitalOcean
  • Docker
  • File
  • Google Cloud
  • Hyper-V
  • Null
  • 1&1
  • OpenStack
  • Parallels
  • ProfitBricks
  • QEMU
  • Triton
  • VirtualBox
  • VMware
  • Custom

There are also so many different ways to provision your images/machines:

  • Ansible Local
  • Ansible Remote
  • Chef Client
  • Chef Solo
  • Converge
  • File
  • PowerShell
  • Puppet Masterless
  • Puppet Server
  • Salt Masterless
  • Shell
  • Shell (Local)
  • Windows Shell
  • Windows Restart
  • Custom

Then when everything is set up you can perform actions using the freshly built image:

  • Alicloud Import
  • Amazon Import
  • Artifice
  • Atlas
  • Compress
  • Checksum
  • Docker Import
  • Docker Push
  • Docker Save
  • Docker Tag
  • Google Compute Export
  • Manifest
  • Shell (Local)
  • Vagrant
  • Vagrant Cloud
  • vSphere

It is truly an amazing tool.

Below is some output that you can expect when using Packer to generate a docker image.

Building with Packer


There is no better tool, it does not matter how good it is, it just depends on how you use it and how well you are able to integrate it within your own workflows. I have used them both tools on different occasions, they both do what they were built to do.

Back to posts