Module 3 - Containers Vs Virtualization (Docker)
Module 3 - Containers Vs Virtualization (Docker)
Module 3 - Containers Vs Virtualization (Docker)
Containers vs Virtualisation
Introduction to Docker
www.newpharma-development.ro
• Containers vs VMs
• What is Docker
Agenda • How to use Docker
• What is Dockerfile
• Containers Orchestration
www.newpharma-development.ro
www.newpharma-development.ro
• Virtualization is the process in which a system singular
resource like RAM, CPU, Disk, or Networking can be
‘virtualized’ and represented as multiple resources.
www.newpharma-development.ro
Containerization is the packaging of software code with just
the operating system (OS) libraries and dependencies required to
run the code.
www.newpharma-development.ro
Bare Metal vs Virtualization vs Containers
www.newpharma-development.ro
What is Docker ?
www.newpharma-development.ro
• Docker is an open-source platform for building, deploying, and
managing containerized applications.
www.newpharma-development.ro
• Dockerfile – simple text file containing instructions for how to
build a docker image
• Docker Image – contains executable application source code, all
the tools, libraries and dependencies that the application code
needs to run as container
• Docker Container – live, running instance of a docker image
• Docker Hub – Docker's official cloud-based registry for docker
images
• Docker Registry – scalable storage and distribution system for
docker images
www.newpharma-development.ro
How to install Docker ?
www.newpharma-development.ro
www.newpharma-development.ro
Docker Usage
www.newpharma-development.ro
Docker Images
• read-only templates with instructions to create a docker container
• can be pulled from a Docker Hub repository
• create your own docker images using a dockerfile
www.newpharma-development.ro
Docker Image Commands
Command Description
www.newpharma-development.ro
Docker Containers
• environments in which you run applications
• defined by the image and any additional configuration options provided
on starting the container
www.newpharma-development.ro
Docker Container Commands
Command Description
www.newpharma-development.ro
Docker Volumes
• preferred mechanism for persisting data generated by and used by
Docker containers
•docker volume create – create a new volume
•docker volume ls – list all the volumes
•docker volume inspect – returns information about a volume
www.newpharma-development.ro
Start a container with a volume
--mount -v or --volume
docker run -d \ docker run -d \
--name devtest \ --name devtest \
--mount source=myvol2,target=/app \ -v myvol2:/app \
nginx:latest nginx:latest
www.newpharma-development.ro
Docker Network
• Docker networking is primarily used to establish
communication between Docker containers and the outside
world via the host machine where the Docker daemon is
running.
Command Description
www.newpharma-development.ro
Repository refers to the hosted collection of the images creating
the file system for containers.
Registry refers to the host containing the repositories and
providing an HTTP API that helps manage the repositories.
• docker login: To log in to a registry.
• docker logout: To log out from a registry.
• docker search: It will search the registry for the image.
• docker pull: It will pull an image from the registry to the local
machine.
• docker push: It will push an image to the registry from the local
machine.
www.newpharma-development.ro
• What is a Dockerfile?
Usages for a Dockerfile
Dockerfile •
• Basic syntax
• Example of a Dockerfile
• Resources
www.newpharma-development.ro
What is a Dockerfile?
www.newpharma-development.ro
Dockerfile usage
www.newpharma-development.ro
Basic syntax
www.newpharma-development.ro
Basic syntax
www.newpharma-development.ro
Basic syntax
• The <WORKDIR> instruction sets the working directory for any RUN,
CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the
Dockerfile
www.newpharma-development.ro
Basic syntax
www.newpharma-development.ro
Basic syntax
• The <COPY> instruction copies new files or directories from <src> and
adds them to the filesystem of the container at the path <dest>
• The <src> path must be inside the directory where the image is build,
executing COPY ../something /something will fail
www.newpharma-development.ro
Basic syntax
• To publish the port when running the container, use the -p flag
on docker run
www.newpharma-development.ro
Basic syntax
www.newpharma-development.ro
Example of a basic Dockerfile
www.newpharma-development.ro
Resources
www.newpharma-development.ro
Containers
Orchestration
www.newpharma-development.ro
Container orchestration is all about managing the lifecycles of
containers.
www.newpharma-development.ro
Docker Compose is a tool for defining and running multi-container
Docker applications.
Installation:
• Install Docker Desktop
• Install Compose plugin
Ex(Debian/Ubuntu): sudo apt-get install docker-compose-plugin
• Install Compose Standalone
https://docs.docker.com/compose/install/other/
www.newpharma-development.ro
Docker Compose works by applying many rules declared within a
single docker-compose.yml configuration file.
version: "3.9"
services:
...
volumes:
...
networks:
...
www.newpharma-development.ro
Command Description
www.newpharma-development.ro
Resources
• https://docker-curriculum.com/
• https://www.docker.com/101-tutorial/
• https://docs.docker.com/
• https://docs.docker.com/engine/install/
www.newpharma-development.ro
Homework
• Install Docker Engine on Ubuntu 22 Machine
• Create a docker container which will execute the bash
script from previous homework
www.newpharma-development.ro
Slack: https://tinyurl.com/e6hjkjsm
Email: [email protected]
www.newpharma-development.ro
Thank you!
www.newpharma-development.ro