Using Packer and Ansible (instead of Dockerfile) to create Docker Images

‹ What is Apache Beam? | What is a variable? ›

Docker contains a feature, the Dockerfile, for automating the creation of images. However, packer can also be used to create docker images, and does so in a way that's generalizes to creating virtual machine or cloud images too.

Here is an example packer file that will create a docker image using an ansible playbook, and tag the image so that you can use it locally.

{
   "builders": [{
      "type": "docker",
      "image": "ubuntu:16.04",
      "commit": true
   }],
   "provisioners": [{
      "type": "shell",
      "inline": [
        "apt-get -y update",
        "apt-get install -y python-minimal sudo"
      ]
   },
   {
      "type": "ansible",
      "playbook_file": "playbook.yml"
   }],
   "post-processors": [[{
      "type": "docker-tag",
      "repository": "wtanaka/mytestimage",
      "tag": "0.1"
   }]]
}

Subscribe to All Posts - Wesley Tanaka