Docker Deep Dive 1710257561
Docker Deep Dive 1710257561
github.com/merndeveloper-hub
linkedin.com/in/owais-yameen-programmer/
BOOK TO FOLLOW
THE BAD OLD DAYS
THE BAD OLD DAYS
● Usually one app one server rule
● Reason were
○ Unable to judge resource requirements
● Disadvantages
○ Very costly
○ Resource wastage
● VMware Workstation, introduced in 1999, was the first product launched by VMware
● This abstraction allows the underlying host machine hardware to independently operate one or
more virtual machines as guests
● This makes it possible for multiple guest VMs to effectively share the system's physical compute
resources, such as
○ Processor cycles,
○ Memory space,
● For a long time, the big web-scale players like Google have been using container technologies to
address these shortcomings of the VM model
■ This frees up huge amounts of system resources such as CPU, RAM, and storage
CONTAINERS (cont…)
○ Licence fee
■ It also reduces potential licensing costs and reduces the overhead of OS patching and other
maintenance
■ Moving container workloads from your laptop, to the cloud, and then to VMs or bare metal in your
data center is a breeze
● Containers result in savings on the cap-ex (Money) and op-ex (Human resource) fronts
TYPE OF CONTAINERS
LINUX
CONTAINERS
LINUX CONTAINERS
● Container technology is not a new phenomenon, and has long been a core feature for Linux
● The advance in recent years of container technology it has become easier to use, and software
developers have embraced them for their simplicity, and avoiding compatibility problems
● They also enable a program to be broken down into smaller pieces, which are known as
microservices
● Just as one example, Google Inc. has contributed many container-related technologies to the
Linux kernel
● Google is not alone, hundreds of individual developers and companies have contributed to linux
kernel
● This means that a container designed to run on a host with a Windows kernel will not run on a
Linux host
● This means that you can think of it like this at a high level - Windows containers require a
Windows Host, and Linux containers require a Linux host
● However, it is possible to run Linux containers on Windows machines. For example, Docker for
Windows (a product offering from Docker, Inc. designed for Windows 10) can switch modes
between Windows containers and Linux containers
DOCKER
IS DOCKER A CONTAINER?
● No!
● Docker, Inc. is a company based out of San Francisco and is the overall maintainer of the
open-source project
● Despite all of this, containers remained complex and outside of the reach of most organizations
● It wasn’t until Docker came along that containers were effectively democratized and accessible to
the masses
● It’s would be not wrong to say that Docker made containers simple!
DOCKER (cont…)
● When most technologists talk about Docker, they’re referring to the Docker Engine
● The Docker Engine can be downloaded from the Docker website or built from source from
GitHub
● It’s available on Linux and Windows, with open-source and commercially supported offerings
● Docker, Inc. also has offers commercial versions of Docker with support contracts etc
● This is a way of saying you can swap out a lot of the native Docker stuff and replace it with stuff
from 3rd parties
● A good example of this is the networking stack that help you connect Docker container together,
or connect them to non-Docker workloads
● The core Docker product ships with built-in networking. But the networking stack is pluggable
meaning you can rip out the native Docker networking and replace it with something else from a
3rd party
THE OPEN
CONTAINER
INITIATIVE (OCI)
THE OPEN CONTAINER INITIATIVE (OCI)
● The OCI is a relatively new governance council organized under the auspices of the Linux
Foundation responsible for standardizing the most fundamental components of container
infrastructure such as image format and container runtime
○ The runtime-spec
● An analogy that’s often used when referring to these two standards is rail tracks
● These two standards are like agreeing on standard sizes and properties of rail tracks
● Leaving everyone else free to build better trains, better carriages, better signalling systems,
better stations... all safe in the knowledge that they’ll work on the standardized tracks
INSTALLING
DOCKER
INSTALL DOCKER CE ON UBUNTU
● Update the apt package index
...
POST INSTALLATION ACTIVITIES
● When you install Docker, you get two major components:
○ the Docker client
○ the Docker daemon (sometimes called “server” or “engine”)
Server:
Engine:
Version: 18.09.2
API version: 1.39 (minimum version 1.12)
Go version: go1.10.4
...
DOCKER ENGINE
DOCKER ENGINE
● The Docker engine is the core software that runs and manages containers
● The Docker engine is modular in design with many swappable components. Where possible, these
are based on open-standards outlined by the Open Container Initiative (OCI).
● The Docker Engine is made from many specialized tools that work together to create and run
containers - images, APIs, execution driver, runtime etc
● The major components that make up the Docker engine are: the Docker client, the Docker
daemon, containerd, and runc. Together, these create and run containers
DOCKER ENGINE
DOCKER ENGINE
The Docker daemon
● The Docker daemon (dockerd) listens for Docker API requests and manages Docker objects such
as images, containers, networks, and volumes
runc
shim
● The shim is integral to the implementation of daemonless containers
● shim makes it possible to perform maintenance and upgrades on the Docker daemon without
impacting running containers!
DOCKER ENGINE
containerd
● containerd act as a bridge between the daemon and runc
● It’s helpful to think of containerd as a container supervisor - the component that is responsible for
container lifecycle operations such as;
○ Starting and stopping containers
● Containerd is designed for a single task in life containerd is only interested container lifecycle
operations
IMAGES
IMAGES
● A Container Image is a lightweight, standalone, executable package of software that includes
everything needed to run an application:
○ Code
○ Runtime
○ System tools
○ System libraries
○ Settings
● Images are made up of multiple layers that get stacked on top of each other and represented as a
single object
IMAGES
● Inside of the image is A cut-down operating system (OS) and all of the files and dependencies
required to run an application
● In this way, each layer contains different things required to run a containerized app
● Common layers among different images are downloaded only once and are stored only once and
get re-use in all images
● You build container based on images and that is why images are sometimes called stopped
containers
● This means that the images they’re built from are usually small and stripped of all non-essential parts
● The official Alpine Linux Docker image is about 4MB in size and is an extreme example of how small
Docker images can be
● Official Ubuntu Docker image which is currently about 120MB. These are clearly stripped of most
non-essential parts
IMAGE REGISTRIES
● Docker images are stored in image registries
● There are many registries options are available, the most common registry is Docker Hub
(https://hub.docker.com)
● Room as Registry
● File racks as repositories
● Files as images
IMAGE REGISTRIES
● Docker Hub also has the concept of official repositories and unofficial repositories
● Official repositories contain images that have been critically examined and verified by Docker, Inc
● Most of the popular operating systems and applications have their own official repositories on
Docker Hub
● You can visit www.hub.docker.com and explore the list of official images and even sign up your
own account which we will be needing to push images you created
● You can then push (upload) images you created to this account and then pull (download) it from
anywhere to use it
● You can even make your uploaded images private which will not let anyone else pull it from you
account
IMAGE NAMING AND TAGGING
● Addressing images from official repositories is as simple as giving the repository name and tag
separated by a colon ( : )
docker image pull <repository>:<tag>
For example: docker image pull nginx:latest
● Pulling images from an unofficial repository is almost the same. You just need to add Docker Hub
username before repository name
2. The latest tag doesn’t have any magical powers! Just because an image is tagged as latest does not
guarantee it is the most recent image in a repository!
PULLING IMAGES
● A cleanly installed Docker host has no images in its local repository
● To pull an image we will use following command
● You can also use docker pull alpine:latest instead of docker image pull alpine:latest
LISTING IMAGE
● Now to see what images you have in your system
● The image ID of any image will be unique and also remain same even if we create new image with
different tag
REMOVING IMAGE
● We have learned that images are use for creating a container
● We have also learned that from one particular image we can create multiple containers that runs
as an instance of that image
● One important thing to remember that once you’ve started a container from an image, the two
constructs become dependent on each other
● You cannot delete the image until the last container using it has been stopped and destroyed
● You can now confirm that the above image is removed from your system
● Technically from image you creates a copy of your app that is now up and running
● In the same way that we can start a virtual machine (VM) from a virtual machine template, we start one
or more containers from a single image
● The big difference between a VM and a container is that containers are faster and more lightweight
● Instead of running a full-blown OS like a VM, containers share the OS/kernel with the host they’re
running on
● You can even containerize big monolithic application but does not benefits you as it does doing
microservices based application
# exit
owais@ap-linux:~$
owais@ap-linux:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
987f94958d57 owais/helloworld "sh" 13 seconds ago Up 10 seconds 80/tcp festive_noether
● Stopping a container does not destroy you data inside file system of container
DOCKER CONTAINERS
● To remove container permanently
● Removing container will now permanently delete files inside container filesystem
● You can even give container a proper name when create by adding --name <name> option in
docker run command
● You can also use -d instead of -it to run you container in background and does not attach shell
after creation but of course you can access shell using docker exec command
Docker
build
Dockerfile
● Docker can build images automatically by reading
the instructions from a Dockerfile
● To achieve above you need to do only one thing, save your image to registry like docker hub
● This saving image is also referred as pushing image to the docker hub
● After creating an account you can simply push your image to docker hub repository
● One thing important to know is for pushing an image to docker hub, we need our images to be
built as username/repository:tag
● Previously we created image with “docker build -t first-docker-app .” which does not include
username
PUSHING IMAGES
● We have two options either we create a new image from same docker file with
OR
● Second option is docker tag command which help make a new image from existing image with
different name tags
● Congratulation! You have uploaded your image to docker hub registry and your image is now
portable
● You can pull your image using docker pull from anywhere in the world and deploy with docker run
command
INSPECTING IMAGE
INSPECTING IMAGE
● To inspect layers of your image
○ docker history <image name>
...
BIND MOUNTS
BIND MOUNT
● By default all files created inside a container are stored
on a writable container layer.
○ Bind mounts
github.com/merndeveloper-hub
linkedin.com/in/owais-yameen-programmer/