Table of contents
- Containers Overview
- Docker
- What is Docker?
- Why Docker?
- This is the story of a Dockerized app
- What is Dockerfile ?
- What is a Docker Image?
- What is a Docker Container?
- What is a Registry?
- What does the complete process look like when using docker?
- Create an app or a service, and build the artifacts
- Docker Installation - we're finally here! -
"Believe it or not, Evergreen vs. the Suez Canal was NOT the biggest container event of the year. #DockerCon is!"
- Docker official page on Facebook.
Containers Overview
What are Containers?
Containers, in short, contain applications in a way that keeps them isolated from the host system that they run on. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and ship it all out as one package.
WE WILL NOT DO THAT!
Just as shipping containers, which allow items to be transported by ship, train, or truck independent of the items inside, software containers act as a standard unit of deployment that can contain different codes and dependencies that can be deployed across different environments.
So why should we use a container?
Containers vs. Virtual Machines
Containers
Containers are an abstraction at the app layer that packages code and dependencies together. Multiple containers can run on the same machine and share the OS kernel with other containers, each running as isolated processes in user space. Containers take up less space than VMs (container images are typically tens of MBs in size), can handle more applications and require fewer VMs and Operating systems.
VMs
Virtual machines (VMs) are an abstraction of physical hardware turning one server into many servers. The hypervisor allows multiple VMs to run on a single machine. Each VM includes a full copy of an operating system, the application, necessary binaries and libraries – taking up tens of GBs. VMs can also be slow to boot.
Containers ≠ Docker
Docker is a Container Engine and not the only one it's not even the first one! But we can say it's almost the best one.
Other Container Engines?
LXC
Rocker
Docker
Docker
What is Docker?
Docker is a platform that packages an application and all its dependencies together in the form of a container image and runs these containers.
When we say dependencies, we mean an application needs a Unix environment, with Java installed, with some scripts or libraries installed, with certain folders created, and an application installed in a specific location.
So a developer can build a container image having different applications installed on it and give it to his peer developers and the QA team. Then the QA team would only need to run the container image to replicate the developer’s environment.
Why Docker?
Consistent development, testing, and deployment.
Fixes the "It works on my machine" problem!
Docker allows for rapid development.
Scalability
- Due to their size, containers can easily and quickly scale to meet demands
Portability
- Applications packaged into Docker Images can run anywhere Docker can be installed
This is the story of a Dockerized app
Once upon a time, a dockerized app was born a Dockerfile, then a developer fellow came and built the docker-file to grow up and become a Docker-Image, After that everyone working on the app took the docker-image and ran it on their machines to finally breathe and become a Docker-Container!
- Ahmed Ayman, 2021 - yeah am quoting myself lol.
What is Dockerfile ?
Text Document with commands telling the docker engine exactly how to build the docker image.
For example, a Dockerfile will have instructions like
Use Unix image as a base image
Update the package-manager repository
Install python
Copy the project files on it
Open ports
Run the app using this command
here is an example Dockerfile of a Flask web app
What is a Docker Image?
A Docker image is a read-only template that contains a set of instructions for creating a container that can run on the Docker platform on any machine that has only Docker installed on it. It provides a convenient way to package up applications
Docker image is created from the Dockerfile. The Dockerfile contains instructions to include environment, framework, artifacts, configurations etc., So the Docker image contains all these.
An image includes everything, from the operating system to all the dependencies (such as frameworks) plus deployment and execution configuration to be used by a container runtime.
Having everything within the image allows you to migrate images between different environments and be confident that if it works in one environment, then it will work in another. "IT WORKS ON MY MACHINE" PROBLEM SOLVED!
What is a Docker Container?
A single running/stopped instance of a docker image.
A container represents the execution of a Single application, process, or service. When scaling a service, you create multiple instances of a container from the same image.
You can think of the relation between the image and its container(s) as many things
The Image is a class, and the container is an object or instance of that class
The image as a Linux distro burned on USB, and the container an installed Linux distro on a machine using this image burned on the USB
The relation between the image and the container is one image to many containers, as the image can have multiple containers spanned from it, but each container can come only from one image.
What is a Registry?
A place to store Docker Images and pull them whenever you want.
A storage and content delivery system, holding named Docker images.
It can be either a user’s local repository or a central repository that is available to the public like Docker Hub, which allows multiple users to share a registry. A little similar to git and GitHub.
Examples:
Azure Container Registry
Google Cloud Registry
Docker Hub ( Default for docker )
What does the complete process look like when using docker?
Create an app or a service, and build the artifacts
Write/Update Docker-file
Build Docker image from Docker-file
Push Docker image to Registry (optional)
Run the Docker image to create a Docker container instance.
Docker Installation - we're finally here! -
Docker Installation Documentation
Docker Installation on Linux
if you don't use Linux, go install Linux then get back kidding you'll find the steps for installing docker on Windows & Mac in the documentation.
Install using the convenience script
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh ./get-docker.sh
- Verify that Docker Engine is installed correctly by running the hello-world image.
$ sudo docker run hello-world
- Create a docker group
$ sudo groupadd docker
- Add your user to the docker group.
$ sudo usermod -aG docker $USER
- Activate the changes to groups
$ newgrp docker
- Verify that you can run docker commands without Sudo
$ docker run hello-world