Dockerfile builder
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Build Status

Crane is a simple tool for building Dockerfiles. It can render templates for you.


cd crane
pip install -e .
crane examples.hello_baby
docker run -i -t hello_baby

Get started

To create a simple building project, here you create a Python package like this

  • hello_baby
    • templates
      • Dockerfile.jinja


from __future__ import unicode_literals

from crane import BuilderBase

class Builder(BuilderBase):

    image_name = 'hello_baby'
    image_version = '0.0.0'
    image_tag = 'latest'

The content of Dockerfile.jinja could be something like this:

FROM phusion/baseimage:0.9.10
MAINTAINER Victor Lin <>

# Set correct environment variables.
ENV HOME /root

ADD /tmp/hello_baby_v{{ builder.image_version }}.sh
RUN chmod +x /tmp/hello_baby_v{{ builder.image_version }}.sh

# Use baseimage-docker's init system.
CMD ["/sbin/my_init", "--", "bash", "-c", "/tmp/hello_baby_v{{ builder.image_version }}.sh"]

It's a jinja2 template file, you can use the variable builder to generate something like your software version into the building process. Besides Dockerfile.jinja, all files suffixed with .jinja in templates folder under that Python package will be rendered to build folder before building the image. Another file we have in this example is

export VERSION='{{ builder.image_version }}'
echo "Current version $VERSION"

And likewiese, you can access builder variable in the template. The example can be found here.