Docker is an open source container management tool that provides a way to run applications in a container.

Containers make it possible to package applications together with their dependencies and libraries and run them in isolation from the host system.

This article contains some hints and tips that will help you when using Docker to create container images for your Workflows, Webapps and development environments.


Contents


Overview

Peak uses Docker containers extensively to run all of the following:

  • Workflows
  • Workspaces
  • Webapps
  • APIs

The benefits of using Docker Containers

  • Consistency:
    Development environments are consistent and predictable and can be worked on by multiple developers.
  • Isolation:
    CPU, memory, storage and network resources are virtualized at the OS-level
  • Fast:
    Automatic scaling and quick to deploy
  • Portability:
    Containers can run in almost any environment.


Docker terminology

Dockerfile

A script containing instructions on how to build an image.


Docker Image

An image contains the instructions for building a container. It is a file comprising multiple layers that is used to execute code in a Docker container; it is like a snapshot of your environment.


Docker Container

This is the instance of the image; a container runs an image.


Docker Daemon

The Docker daemon is a service that runs on your host operating system.


Dockerfile basics


Python

FROM python:3.7-slim
# single line comment - the slim images are smaller

RUN apt-get update -qq \
&& apt-get install -y --no-install-recommends \
git

ARG GITHUB_TOKEN
RUN pip install git+https://$GITHUB_TOKEN@github.com/PeakBI/orion.git@0.5.5

WORKDIR code
COPY . .
RUN python setup.py install
  • FROM
    Indicates which image we want to use as a base
  • RUN
    Executes a command
  • COPY
    Copies files
  • WORKDIR
    Changes the current working directory
  • ARG
    A build argument with this name (does not save to the image).
    Access it by $NAME
  • \
    A line continuation (split commands over multiple lines)
  • &&
    Means run this command after the previous one succeeds


R

FROM rocker/tidyverse:3.6.2

RUN apt-get update -qq \
&& apt-get -y --no-install-recommends install \
awscli \
cmake \
git \
unixodbc-dev

ARG BUILD_CPUS=4

RUN git clone --recursive https://github.com/microsoft/LightGBM --branch v2.3.1 \
&& cd LightGBM \
&& Rscript build_r.R \
&& Rscript -e "install.packages(c('odbc', 'logger', 'plotROC', 'zoo'), Ncpus=$BUILD_CPUS)"
  • FROM
    Indicates which image we want to use as a base
  • RUN
    Executes a command
  • COPY
    Copies files
  • WORKDIR
    Changes the current working directory
  • ARG
    A build argument with this name (does not save to the image).
    Access it by $NAME
  • \
    A line continuation (split commands over multiple lines)
  • &&
    Means run this command after the previous one succeeds


Using Build Arguments and Environment Variables

The current default build arguments are shown in Image Management:


Additional build arguments can be added:


If you want to access Peak repos to install packages, you will need to provide a (personal) GitHub token. 


Docker file argument examples

Build Arguments:

docker build -t <image_name>:<tag> --build-arg ARG_NAME=<arg_value>
docker build -t coolest_image_ever --build-arg GITHUB_TOKEN=abc --build-arg CPU_COUNT=8 


Environment Variables:

docker run -e <ENV_VAR_NAME>=<value> <image_name>:<tag> <command>
docker run -e API_KEY=abc1234 coolest_image_ever Rscript app.R

Further information