Intro

Docker is the absolute whale in the containerization space…I won’t do this again, I promise. I’ve dabbled with it before here and there but I know enough to know that I actually don’t… So I’ll be following the Docker Curriculum guide and various YouTube vids.

What is Docker?

It’s an OpenSource project for deploying and running software inside containers. This is an abstraction level above the OS of the machine. Docker only runs, natively, on Linux machines. This abstraction is known as Containerization

Mac and Windows

Docker runs on these operating systems using an app called Docker Desktop which just runs Linux VMs…

Docker Daemon and Client

  • The Docker Daemon is the background service running on the host, in most cases your machine, that manages building, running and distributing Docker containers. The daemon runs on the host OS, and is what the Docker clients talk to.

Daemon is a term for a persistent background process.

  • Docker Client , often a CL tool, that allows us to interact with Docker, the daemon to exact. There are various clients including the default Docker Desktop client for Windows.

When To Use Docker?

This article does a dive into when to use it and when not to. Link.

What’s a Container?

Containers allow us to bundle a program along with all its dependencies together in an encapsulated environment.

Containers vs VMs

Containers don’t have the heavy overhead commonly associated with VMs, making them more efficient and portable for sharing and deploying programs, by reducing the resources needed from the underlying system.

VM tangent

A VM app runs inside the guest OS, which is run on virtual hardware powered by thehost machine (the actual computer and its hardware). A VM is great if you need FULL isolation of the applications, to live in their own walled garden. However, these apps can be negatively affected by the host OS, and the computational overhead is expensive and non-trivial.

Containers abstract the environment the apps need from the one they actually run on, uncoupling them from it and making deployment much easier by making predictable environments that run anywhere.

w:400 // The previous illustration simplifies a lot but it’s not too far off.

The Parts

Dockerfiles

Whereas, DockerFiles are the files (blueprints) that outline the specific commands needed to produce the Docker Image, since these commands are declared, this allows for reproducibility and portability. A Dockerfile that’s unchanged, will always produce the same Docker Image. Check out Writing a Dockerfile.

Images

Think of DockerImages like the schematics for your container, they contain all the information needed to set up the container and for your app to run within it. Images have tags that are used to specify the version (but can be named anything really) and the default is “latest”.

Types

  • Base images have no parent image, usually images with an OS like ubuntu, busybox or debian.
  • Child imagesthese are built on top of base images and add additional functionality and features.
  • Official images are images that are officially maintained and supported by Docker themselves. These are typically one word long. Examples include the python, ubuntu, busybox and hello-world images as found on Docker Hub.
  • User images are created and shared by users, and are also built on Base Images. Typically, these are formatted as user/image-name.

Contents

The images may contain a plethora of things, but here are the most common.

  • OS
  • Dependencies
  • Project code

Docker images aren’t actual file or data type, they’re a snapshot (hence the name), of the libraries and dependencies needed to run the app in a container. The instructions to recreate this image are in a dockerfile.

Containers

Images alone don’t do anything, they need to be run as a container. The container is the isolated environment that runs your service/code and can be scaled accordingly.

Container’s are also stateless, meaning once it’s shut down, all the state is lost. This is by design, as it makes them very portable and be run every where.

Docker Hub

An online repository of Docker images to pull from and push to. Users can share useful and neat images for others to use. Check out.

Modes

  1. Detached mode lets a container run detached from the terminal instance that was used to spin it up, so when that terminal is closed the container continues running. Use the -d option with the run command to flag a container as detached.

Docker Commands

All the commands can be invoked with the flag --help for more info on them such as options and outputs.

  • Running a docker container using docker run imageName. It runs a container using the provided image name. more Running the run command with the -it flags attaches us to an interactive “TTY” in the container. The --rm option flags a container for automatic deletion upon exiting. Very useful.
  • docker images : shows all the images stored on your machine.
  • docker ps : shows all running containers on your machine. Use the -a option flag for more more information.
  • exit is used to exit from an interactive TTY container, like if you had a UNIX system running in a container.
  • docker rm containerID : deletes that specific container. Good for cleanup. Can delete multiple by passing multiple IDs separated by space. To delete all containers that have exited (completed) use: docker rm $(docker ps -a -q -f status=exited)
  • Stopping a container use docker stop containerID

References