Coder Social home page Coder Social logo

dockermake's Introduction

DockerMake

Compose docker containers using human-readable YAML files.

Written by:
Aaron Virshup
Bio/Nano Research Group
Autodesk Research

Requirements

You'll need python2.7, pyyaml, docker-py, and access to a docker daemon. If you have pip and a docker-machine, you can run these commands to get set up:

pip install pyyaml docker-py
eval $(docker-machine env [machine-name])

Example

There are 5 docker images to be built in this example. devbase is just basic compilation tools. airline_data adds a large CSV file to devbase. python_image installs some basic data science tools on top of devbase. data_science combines both airline_data and python_image to give you a docker image with both the data and the tools.

Here's the DockerMake.yaml file for this build:

devbase:
 FROM: phusion/baseimage
 build: |
  RUN apt-get -y update && apt-get -y install build-essential

airline_data:
 requires:
  - devbase
 build_directory: sample_data/airline_data
 build: |
  ADD AirlinePassengers.csv
  
python_image:
 requires:
  - devbase
 build: |
  RUN apt-get -y update \
  && apt-get install -y python python-pip \
  && pip install pandas
  
data_science:
 requires:
  - python_image
  - airline_data

To build an image called alice/data_science, you can run:

docker-make.py --user alice data_science

which will create an image with all the commands in python_image and airline_data.

This works by dynamically generating a new Dockerfile every time you ask to build something. However, most of the commands will be cached, especially if you have a large hierarchy of base images. This actually leads to less rebuilding than if you had a series of Dockerfiles linked together with FROM commands.

Writing DockerMake.yaml

The idea is to write dockerfile commands for each specific piece of functionality in the build field, and "inherit" all other functionality from a list of other components that your image requires. If you need to add files with the ADD and COPY commands, specify the root directory for those files with build_directory. Your tree of "requires" must have exactly one unique named base image in the FROM field.

[image_name]:
  build_directory: [relative path where the ADD and COPY commands will look for files]
  requires:
   - [other image name]
   - [yet another image name]
  FROM: [named_base_image]
  build: |
   RUN [something]
   ADD [something else]
   [Dockerfile commands go here]

[other image name]: ...
[yet another image name]: ...

Command line usage

usage: docker-make.py [-h] [--pull] [-f MAKEFILE] [-u USER] [-p] [-n] [-a]
                      [-l]
                      [TARGETS [TARGETS ...]]

NOTE: Docker environmental variables must be set. For a docker-machine, run
`eval $(docker-machine env [machine-name])`

positional arguments:
  TARGETS               Docker images to build as specified in the YAML file

optional arguments:
  -h, --help            show this help message and exit
  --pull                Pull updated external images
  -f MAKEFILE, --makefile MAKEFILE
                        YAML file containing build instructions
                        (default: DockerMake.yaml)
  -u USER, --user USER  Append this user tag to all built images, e.g.
                        `docker_make hello-world -u elvis` will tag the image
                        as `elvis/hello-world`
  -p, --print_dockerfiles
                        Print out the generated dockerfiles named
                        `Dockerfile.[image]`
  -n, --no_build        Only print Dockerfiles, don't build them. Implies
                        --print_dockerfiles.
  -a, --all             Print or build all dockerfiles in teh container
  -l, --list            List all available targets in the file, then exit.

Copyright (c) 2015, Autodesk Inc. Released under the simplified BSD license.

dockermake's People

Contributors

avirshup avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.