PyAll. Or a Docker Container built with Packer and Ansible with all Python versions

  • Fri 02 January 2015

  • I'll often use a pet project as an excuse to play with a new technology, so this was largely a proof of concept of Packer.

    A pet project of mine needs an environment with all the versions of Python (2.6, 2.7, 3.4, 3.5, 3.6, 3.7 and PyPy). I built a Docker container back in the day with a DockerFile. Dockerfiles absolutely work, there were some limitations, I haven't followed the project closely to know if they've been "fixed".

    Packer uses a JSON template to define a VM or Container. A template is made up of builders, provisioners, post-processors and variables Packer has many builders and one of the supported builders is Docker. A builder simply defines the platform or technology (EC2/DO/Docker/GCE/OS/Paralles/QEMU/VB/VMware/Custom) to build the VM or Container on.

    If you're familiar with Vagrant (same project creator), Packer also has provisioners. Supported provisioners are shell scripts, file uploads, Ansible, Chef Client & Solo, both Puppet Masterless and Server, as well as Salt and a custom provisoner. Ansible is my go-to configuration management tool today (though the more I use it, the more I miss Salt and Chef).

    Here is what my template.json looks like:

            "builders": [
                            "type": "docker",
                            "image": "ansible/ubuntu14.04-ansible:stable",
                            "commit": true
            "provisioners": [
                            "type": "ansible-local",
                            "playbook_file": "provisioning/container.yml"
                            "type": "docker-tag",
                            "repository": "esacteksab/pyall",
                            "tag": "0.12"

    A quick "what does this all mean":

    In builders I use the type of docker and am using Ansible's Docker image from their Github repo (this gets us past the need for an initial shell provisioner in the Packer template to install Ansible before we use the Ansible provisioner).

    I define an ansible-local provisioner in the provisioners block, then define the path to my Ansible playbook.

    Once the container is created, and the playbook is provisioned, I leverage a post-processor with a type of docker-tag which simply tags the container and makes it easier to manage from Docker's perspective.

    How to build container:

    You build the container with something like:

    $ sudo packer build template.json

    Once the container is created, I can simply do a:

    sudo docker push esacteksab/pyall:0.12

    Then the container exists here on the Docker hub

    Comments !