What and Why

A container, powered by the containerization engine, is a standard unit of software that encapsulates the application code, runtime, system tools, system libraries, and settings necessary for programmers to build, ship, and run applications efficiently.

FeaturesDescription
Isolation and AllocationNo way to define resources boundaries for apps in a physical server
Server UtilizationNot optimal because server tend to be either over-utilized or under-utilized
Provisioning and CostRequires long periods for provisioning resources and expensive maintenance costs
PerformanceConstrained during peak workloads
PortabilityApplications are not portable across multiple environments and operating systems
ResiliencyComplex, time-consuming and expensive
ScalabilityLimited scalability and resiliency
AutomationDifficult to implement for multiple platforms

Characteristics

Challenges

  • Security impacted if operating system affected
  • Difficult to manage thousands of containers
  • Complex to migrate legacy projects to container technology
  • Difficult to right-size containers for specific scenarios

Vendors

  • Docker - Robust and most popular container platform today
  • Podman - Daemon-less architecture providing more security than Docker containers
  • LXC - Preferred for data-intensive apps and ops
  • Vagrant - Offers highest levels of isolation on the running physical machine

Docker

Docker is an open platform, or engine, written in Go programming language, uses Linux kernel’s features and namespaces technology to provide isolated workspace, where programmers can Develop -> Ship -> Run -> Containers. Docker became popular because:

  • Simple architecture
  • Scalability
  • Easy portability

Docker Commands

Docker Objects

Dockerfile

is a text file that contains instructions needed to create an image.

  • FROM - Defines base image, always begin from this instructions.
  • RUN - Executes arbitrary commands
  • CMD - Defines default command for container execution

CMD should always have one command instructions. If multiple CMD instructions then only the last command instruction will take effect.

Image

layers can be shared between images, which saves disk space and network bandwidth.

Naming

      hostname/repository:tag
        ^         ^        ^
      /           |          \
  Image       Container    Version
 Registry      Images   or Variant of Image


e.g. docker.io/ubuntu:18.04

The host name can be excluded using Docker CLI.

Container

  • is runnable instance of an image
  • can be created, stopped, started or deleted using the Docker API or CLI
  • can connect to multiple networks, attach storage, or create a new image based on its current state
  • is well isolated from other containers and its host machine

Network

  • Networks are used for the isolated containers communication

Storage

  • Docker uses volumes and bind mounts to persist data even after a container stops

Plugins

  • Storage plugins provide the ability to connect to external storage platforms

Docker Architecture

consists of a Docker client, a Docker host, and a registry.

  • based on client-server architecture
  • provides a complete application environment
  • includes the client, the host, and the registry components
  • Docker host server include Docker daemon known as dockerd
Docker CLI or REST APIs -------> Docker host server
                  sends instructions

Daemon <----- Docker API requests or "docker run" commands
       listens

The daemon ----------------> to the registry
    builds, runs, and distributes containers

Registry ----------> images (either public or private)
          stores

Registry

  • stores and distributed images, public (Docker Hub), private (implemented for security).
  • registry locations are either hosted or self-hosted.

Commands

CommandDescription
curl localhostPings the application.
docker buildBuilds an image from a Dockerfile.
docker build . -tBuilds the image and tags the image id.
docker CLIStart the Docker command line interface.
docker container rmRemoves a container.
docker imagesLists the images.
docker psLists the containers.
docker ps -aLists the containers that ran and exited successfully.
docker pullPulls the latest image or repository from a registry.
docker pushPushes an image or a repository to a registry.
docker runRuns a command in a new container.
docker run -pRuns the container by publishing the ports.
docker stopStops one or more running containers.
docker stop $(docker ps -q)Stops all running containers.
docker tagCreates a tag for a target image that refers to a source image.
docker –versionDisplays the version of the Docker CLI.
exitCloses the terminal session.
export MY_NAMESPACEExports a namespace as an environment variable.
git cloneClones the git repository that contains the artifacts needed.

IBM Specific Commands

CommandDescription
ibmcloud cr imagesLists images in the IBM Cloud Container Registry.
ibmcloud cr loginLogs your local Docker daemon into IBM Cloud Container Registry.
ibmcloud cr namespacesViews the namespaces you have access to.
ibmcloud cr region-setEnsures that you are targeting the region appropriate to your cloud account.
ibmcloud targetProvides information about the account you’re targeting.
ibmcloud versionDisplays the version of the IBM Cloud CLI.