Skip to content
This repository has been archived by the owner on Jan 25, 2021. It is now read-only.

jboss-dockerfiles/dock

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dock

Python library with command line interface for building docker images.

Features

  • push image to registry when it's built
  • build inside a docker container (so your builds are separated between each other)
  • git as a source to your dockerfile (you may specify commit/branch and path to Dockerfile within the git repo)
  • collect build logs
  • integration with koji build system
  • integration with fedora packaging system
  • inject arbitrary yum repo inside dockerfile (change source of your packages)
  • retag base image so it matches FROM instruction in dockerfile
  • change base image (FROM) in your dockerfile
  • run simple tests after your image is built

There are several build modes available:

  • building within a docker container using docker from host by mounting docker.sock inside the container
  • building within a privileged docker container (new instance of docker is running inside)
  • executing build within current environment

Installation

for Fedora users

$ yum install dock dock-koji

from git

Clone this git repo and install dock using python installer:

$ git clone https://github.com/DBuildService/dock.git
$ cd dock
$ sudo pip install .

You don't even need to install it. You may use it straight from git:

$ export PYTHONPATH="${DOCK_PATH}:${PYTHONPATH}"
$ alias dock="python ${DOCK_PATH}/dock/cli/main.py"

Dependencies

  • GitPython
  • docker-py.
  • koji plugin requires koji package, which is not available on PyPI: you have to install it manually:
$ yum install koji

Usage

If you would like to build your images within build containers, you need to obtain images for those containers. We call them build images. dock is installed inside and used to take care of build itself.

At some point, these will be available on docker hub, but right now, you need to build them yourself.

installation from git

$ dock create-build-image --dock-local-path ${PATH_TO_DOCK_GIT} ${PATH_TO_DOCK_GIT}/images/dockerhost-builder buildroot

Why is it so long? Okay, let's get through. First thing is that dock needs to install itself inside the build image. You can pick several sources for dock: your local copy, (this) official upstream repo, your forked repo or even distribution tarball. In the example above, we are using our locally cloned git repo (--dock-local-path ${PATH_TO_DOCK_GIT}).

You have to provide dockerfile too. Luckily these are part of upstream repo (see folder images). It's the first argument: ${PATH_TO_DOCK_GIT}/images/dockerhost-builder.

And finally, you need to name the image: buildroot.

installation from RPM

$ dock create-build-image --dock-tarball-path /usr/share/dock/dock.tar.gz /usr/share/dock/images/dockerhost-builder buildroot-fedora

Section above contains detailed description. Let's make this short.

  1. --dock-tarball-path — dock needs to install itself into build image: this is how you specify where dock gets its own sources (when installed via RPM, dock provide itself packaged as tarball at /usr/share/dock/dock.tar.gz)
  2. first argument is path do dockerfile — dockerfiles for both methods are available at /usr/share/dock/images/, just pick one
  3. and finally, second argument names the build image

getting dock from distribution

Or you can build the image using docker and install dock directly from distribution:

FROM fedora:latest
RUN yum -y install docker-io git python-docker-py python-setuptools GitPython koji dock
CMD ["dock", "-v", "inside-build", "--input", "path"]

and command:

$ docker build -t buildroot-hostdocker .

And now you can build your images!

As soon as our build image is built, we can start building stuff in it:

$ dock build --method hostdocker --build-image buildroot --image test-image --git-url "https://github.com/TomasTomecek/docker-hello-world.git"

Built image will be in the build container. Therefore this example doesn't make much sense. If you would like to access the built image, you should probably push it to your registry and build it like this:

$ dock build --method hostdocker \
             --build-image buildroot \
             --image test-image \
             --target-registries 172.17.42.1:5000 \
             --git-url "https://github.com/TomasTomecek/docker-hello-world.git"

IP address 172.17.42.1 should be address of docker0 network interface. Update it if yours is different. Also, don't forget to start the registry.

Bear in mind that you shouldn't mix build methods: if you use hostdocker method with build image for privileged method, it won't work.

Further reading

About

Simple python library for building docker images.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 97.7%
  • Shell 2.3%