What is Container?
➡ A way to package an application with all the necessary dependencies and configuration.
➡ Portable standardized artifact for development, shipment and deployment.
➡ Makes development and deployment more efficient.
What is Docker?
◙ Docker is an open-source containerization platform.
◙ Enables developers to package applications into containers.
◙ Containers existed already before Docker.
◙ Docker made containers popular.
Where container artifacts are hosted
➡Hosted in container repositories.
➡There are private and public repositories.
➡Public repository for Docker: Docker Hub
Application DEVELOPMENT before and after Docker
Before Containers
The Installation process is different in each OS environment.
Many steps where something could go wrong.
Configuration on the server needed:- Dependency version conflicts.
Textual guide for deployment:- Misunderstanding.
After Containers
Own isolated environment.
Packaged with all needed configurations.
Easily run the same application with two different versions.
one command to install the same application.
No environment configuration is needed on the server (except Container Runtime).
Devs & Ops work together to package the application in a container.
Docker = most popular container technology
Other
Containerd
cri-o
Docker Image vs Docker Container
Docker Image
The actual package (file).
The Artifact can be moved around.
Not a "running" state.
Consists of several layers.
Mostly Linux Base Image, application image on top.
Images become containers at runtime
Docker Container
starts the application.
Is a running environment defined in the image.
Virtual file system.
Port binding: talk to an application running inside of the container.
Containers vs Virtual Machines
Size: Docker Image is much smaller.
Speed: Docker containers start and run much faster.
Compatibility: VM of any OS can run on any OS host.
Both are virtualization tools.
Components of Docker
Docker client and server
Docker image
Docker registry
Docker container
Advanced Docker Components
Docker compose
Docker swarm
Docker Architecture
Docker Engine:-
Server- ⦿ Pulling Images.
⦿ Managing Images and Containers.
API- ⦿ Interacting with Docker Server.
CLI- ⦿Command Line Interface: Client to execute Docker commands.
Server:-
Container Runtime- ⦿ Pulling images.
⦿ Managing container lifecycle
Network- ⦿ Configuring network for container communication
Volumes- ⦿ Persisting data
Also, Build Images.
Main Docker Command
➊ docker run: creates a container from an image.
➋ docker pull: pull images from the docker repository.
➌ docker start: starts one or more stopped containers.
➍ docker stop: stops a running container.
➎ docker images: lists all the locally stored docker images.
➏ docker ps: lists the running containers.
➐ docker ps -a: show all the running and exited containers.
Debug Commands
➊ docker logs: fetch logs of a container.
➋ docker exec -it: creates a new bash session in the container.
Container Image
An image of a container contains the application, its dependencies and the operating system where the application is executed.
It's a collection of read-only layers. These layers are loosely coupled
- Each layer is assembled out of one or more files.
In which scenarios would you use containers and in which you would prefer to use VMs?
You should choose VMs when:
You need to run an application that requires all the resources and functionalities
of an OS.
You need full isolation and security.
You should choose containers when:
You need a lightweight solution.
Running multiple versions or instances of a single application.