Docker Feature

Adds docker capabilities to your package, using either “docker build” or “rocker build” to create an image containing your code, in a fully functionnal python virtualenv.

Usage

To use the Docker Feature, make sure your Projectfile contains the following:

from medikit import require

docker = require('docker')

The docker handle is a DockerConfig instance, and can be used to customize the feature.

This feature is brand new and should be used with care.

You’ll get a few make targets out of this, and a Dockerfile (or Rockerfile).

Build

Building an image is as simple as running:

$ make docker-build

This will use the root Dockerfile (or Rockerfile, see builders below) and build an image named after your package.

Push

You can push the built image to a docker registry, using:

$ make docker-push

Run

You can run the default entrypoint / command in a new container using the built image:

$ make docker-run

Shell

You can run a bash shell in a new container using the built image:

$ make docker-shell

Custom builder

You can change the default docker builder (a.k.a “docker build”) to use rocker (see https://github.com/grammarly/rocker).

docker.use_rocker_builder()

Custom image name or registry

If you want to customize the image name, or the target registry (for example if you want to use Amazon Elastic Container Registry, Google Container Registry, Quay, or even a private registry you’re crazy enough to host yourself):

# only override the registry
docker.set_remote(registry='eu.gcr.io')

# override the registry and username, but keep the default image name
docker.set_remote(registry='eu.gcr.io', user='sergey')

# override the image name only
docker.set_remote(name='acme')

Docker Compose

The feature will also create an example docker-compose.yml file.

If you don’t want this, you can:

docker.compose_file = None

Or if you want to override its name:

docker.compose_file = 'config/docker/compose.yml'

Please note that this file will only contain a structure skeleton, with no service defined. This is up to you to fill, although we may work on this in the future as an opt-in managed file.

Configuration

class medikit.feature.docker.DockerConfig[source]
build_file
compose_file
disable_builder()[source]
image
set_remote(registry=None, user=None, name='$(shell echo $(PACKAGE) | tr A-Z a-z)')[source]
use_default_builder()[source]
use_rocker_builder()[source]
variables

Implementation

class medikit.feature.docker.DockerFeature(dispatcher)[source]
Config

alias of DockerConfig

on_end(event)[source]

Listens to medikit.on_end event (priority: 0)

on_make_generate(event)[source]

Listens to medikit.feature.make.on_generate event (priority: -1)