0% found this document useful (0 votes)
588 views37 pages

02 Containers and Docker

Docker allows packaging applications and their dependencies into standardized units called containers. Containers can be run on any machine that supports Docker. The Docker CLI allows building, running, and managing containers from the command line. Volumes are used to persist data generated by containers.

Uploaded by

Ludmil Iordanov
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
588 views37 pages

02 Containers and Docker

Docker allows packaging applications and their dependencies into standardized units called containers. Containers can be run on any machine that supports Docker. The Docker CLI allows building, running, and managing containers from the command line. Volumes are used to persist data generated by containers.

Uploaded by

Ludmil Iordanov
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

Docker and Containerization Basics

Package App + Dependencies +


Configurations as Containers

Technical Trainers
SoftUni Team
Software University
https://about.softuni.bg
Have a Question?

sli.do
#Dev-Ops
2
Table of Contents

1. Containerization
2. Docker
3. Docker CLI
4. File System and Volume

3
Containerization
Overview, VMs VS Containers, Advantages
Containerization
▪ Containerization == approach in which an app or service is
packaged as a container
▪ Image == read-only template that contains a set of instructions for
creating a container
▪ It contains software, packaged with its dependencies
and configuration
▪ Designed to run in a virtual environment
▪ Container == a runnable instance of an image
5
VMs vs Containers
▪ VMs virtualize the hardware ▪ Containers virtualize the OS
▪ Complete isolation ▪ Lightweight isolation
▪ Complete OS installation. Utilization ▪ Shared kernel. Requires
Requires more resources fewer resources
App 1 App 2 App 3 App 1 App 2 App 3
Bins/Lib Bins/Lib Bins/Lib Size Bins/Lib Bins/Lib Bins/Lib
Guest OS Guest OS Guest OS Container Engine
Hypervisor Operating System
Boot Up Time
Infrastructure Infrastructure
6
Containerization – Advantages
▪ Easily deploy across environments with little or
no modification
▪ Immutability
▪ Once a container is created, it doesn't change
▪ To make a change, a new container must be created
▪ Ensures consistency across different environments
▪ Portability
▪ Depend of container runtime, not underlying infrastructure
▪ Run on any machine that supports the container runtime
7
Containerization – Advantages
▪ A containerized app can be tested and deployed as a unit to
the host OS
▪ Resource-efficient
▪ Share the same OS kernel and isolate applications from
each other
▪ Scalability
▪ Can be easily scaled up or down
▪ Orchestrated by special tools
▪ More on that later
8
Docker
Docker Images, Containers, Software Development
Docker
▪ Docker == lightweight, open-source, secure
containerization platform
▪ It simplifies building, shipping and running
applications
▪ On different environments
▪ Runs natively on Linux or Windows servers
▪ Runs on Windows or Mac development machines
▪ Relies on images and containers
10
Docker Image
▪ Docker image == blueprint for a container
▪ A read-only template, used to create containers
▪ If you want to change something, you should create a new image
▪ Holds app/service/other software
▪ Framework, dependencies and code are "described" here
▪ Docker registry == a repository for images

11
Docker Container
▪ Built from the image
▪ Images become containers at runtime
▪ It is the actual running environment for your app
▪ Isolated and secured
▪ It can be started/stopped/deleted
▪ Different app components may reside in separate containers
▪ Database, back-end, front-end, caching, messaging, etc.
12
Docker Desktop
▪ Out-of-the-box containerization software
▪ Runs on Windows or Mac development machines
▪ Includes Docker Engine, CLI and Kubernetes
▪ Complete Docker development environment
▪ Containerize any application
▪ Build
▪ Share
▪ Run
13
Docker Desktop
▪ On Windows
▪ Ability to switch between Linux
and Windows Server environments
▪ Typically runs Linux containers
through WSL2 technology
(Windows Subsystem for Linux)
▪ https://docs.docker.com/desktop/install/windows-install
▪ There are third-party solutions for Linux – DockStation,
CairoDock, and more…
14
Docker Hub
▪ Docker Hub == cloud-based image repository (registry)
▪ Used for easy finding and sharing images
▪ Supports public and private repositories
▪ Automated builds and webhooks
▪ For every tool we use in Docker, it is recommended that we
read its documentation first
▪ As sometimes we need to perform configurations to work
with the tool

15
Docker Compose
▪ Some apps combine multiple components
▪ e.g., WordPress requires Linux + NGINX + PHP
+ MySQL
▪ Each component may run in a separate
Docker container
▪ To run multiple connected containers, we use
Docker Compose

16
Development Workflow for Docker Apps

Registry / hub
17
Docker CLI
Command Line Tool to Talk to the Docker Daemon
Docker CLI
▪ Docker CLI allows working with the Docker Engine
▪ Build and manage images
▪ Run and manage containers
▪ Example commands
docker pull [image]
docker run [image]
docker images
docker ps
docker logs [container]
19
Live Demo
NGINX Server Container
File System and Volume
Data in Docker Containers
Layered File System
▪ Each image has file system layers, which are read-only and isolated
Thin R/W Layer
Container ▪ Image layers are reused in
Layer different images
Image
91e54dfb1179
d74508fb6632 Layer exists from
Image Layers another image
c22013c84729 (read-only)
d3a1f33e8a5a

Ubuntu
Image layers
Container, based on Ubuntu
22
Layered File System
▪ Images share layers
▪ Therefore they load faster once you have them

91e54dfb1179 Thin R/W Layer


Thin R/W Layer
d74508fb6632
c22013c84729
Thin R/W Layer
d3a1f33e8a5a
Thin R/W Layer Ubuntu
Thin R/W Layer
23
Container Isolation
▪ Each container is isolated and has its own writable file system
▪ By default, file system is deleted after you delete
the container Delete old
container
▪ Which is not very suitable for persistence operations and create
a new one

test.txt file
is missing

24
Volumes
▪ To persist data, use volumes
Writable Layer
▪ Special type of directory on the host
▪ Mapped to the real file system C:\ Image Layer
▪ Can be shared and reused Base Layer
among containers
▪ Image updates won't
affect volumes
▪ Persisted even after the
container is deleted
G:\ Volume
▪ You have full control over them
25
Attach Local Folder as Volume
▪ Attach local folder as volume to a container
docker run -p 5001:80 -d -v c:\users:/app nginxdemos/hello

▪ Examine mapped container's /app folder

/app has files


from c:\users

26
Creating and Using Volumes
▪ Create a volume
docker volume create myvolume

▪ List all volumes


docker volume ls

27
Creating and Using Volumes

▪ Inspect volume
docker volume inspect myvolume

28
Creating and Using Volumes
▪ Mount volume to container
docker run -p 5000:80 -d -v myvolume:/myapp nginxdemos/hello

▪ Create a file in the /myapp folder

29
Creating and Using Volumes
▪ Remove volume
▪ A volume that is in use cannot be removed
▪ You can remove multiple volumes simultaneously
docker volume rm myvolume

Should not be in use

30
Live Demo
Vue.js App in a Container
Live Demo
Docker Container with MongoDB
Summary
▪ …
▪ With Docker we can create and manage images,
▪ … containers, volumes, etc.
▪ Image == read-only template with instructions
▪ … for creating a Docker container
▪ Container == a runnable instance of an image
▪ Volumes == the preferred mechanism for
persisting data
▪ We can run apps in containers
▪ We can also have a working database
in a container
33
Questions?
SoftUni Diamond Partners
License

▪ This course (slides, examples, demos, exercises, homework,


documents, videos and other assets) is copyrighted content
▪ Unauthorized copy, reproduction or use is illegal
▪ © SoftUni – https://about.softuni.bg/
▪ © Software University – https://softuni.bg

36
Trainings @ Software University (SoftUni)
▪ Software University – High-Quality Education,
Profession and Job for Software Developers
▪ softuni.bg, about.softuni.bg
▪ Software University Foundation
▪ softuni.foundation
▪ Software University @ Facebook
▪ facebook.com/SoftwareUniversity
▪ Software University Forums
▪ forum.softuni.bg 37

You might also like