Docker

17 Dec 2020

Docker is a convenient technology to create portable isolated and reproducible runtime environments for design-time development and production hosting of applications

Main technology concepts

Docker is an abstraction technology which isolates an applications runtime environment from host infrastructure, and thereby increases the applications portability by encouraging applications which run upon a Docker Engine, on any host.

This increases uniformity, aids reproduction, decreases host specific configuration needs and aids development in isolation.

Docker hosts are different to virtual machine hosts

Image

Container

Docker Engine

Docker Engine

Docker Architecture

Docker containers communicate with the Docker daemon which acts upon the host OS and infrastructure, to maintain the lifecycle and provide application communication needs

Architecture

Docker Hub

Docker Swarm

Docker Swarms enable applications to be quickly scaled over docker hosts which have swarm capabilities enabled.

Swarms can be considered a mechanism for getting multiple instances of an application to run concurrently.

Docker Swarm manages host networking, load balancing, service discovery, scaling on behalf of the application administrator.

Kubernetes

Kubernetes is a Google technology which automates deployment, scaling and management of containerized applications. You can use Kubernetes to manage Docker container application lifecycles instead of Docker Swarm, however they are separate technologies,are independent of each other and require different deployment concepts.

Dockerfile

A Dockerfile is a recipe for building a container image

FROM python:3.7-alpine
WORKDIR /code
ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0
RUN apk add --no-cache gcc musl-dev linux-headers
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
EXPOSE 5000
COPY . .
CMD ["flask", "run"]

Dockerfile keywords

Docker Compose

A docker-compose.yml file describes how to deploy containers and the associated dependencies

version: "3.9"
services:
  web:
    build: .
    ports:
      - "5000:5000"
  redis:
    image: "redis:alpine"

Start with a simple command line operation

docker-compose up

Detached mode startup

docker-compose up -d

When using detached mode startup, the docker composition can be stopped without removing the container or dependencies

docker-compose stop

Stop just as easily, removing all the containers and dependencies in one step

docker-compose down

Overview

Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.

Docker CLI

Run an instance of the ubuntu docker image, and create an interactive session to a bash shell

docker run -i -t ubuntu /bin/bash

Cheat Sheet Source

Acknowledgements - Cheat Sheet

CI/CD with Docker

CI/CD

Acknowledgements to Docker