0% found this document useful (0 votes)
45 views33 pages

Containers Shyam

Docker is a platform for developing, deploying and running applications using containers. Containers allow applications to be packaged with all dependencies and run consistently regardless of environment. Key Docker commands allow users to run, stop, list and remove containers. Docker images contain the contents of containers and are built using Dockerfiles which specify build instructions through commands like FROM, RUN and CMD. Containers provide benefits like being lightweight, portable and efficient compared to traditional virtual machines.

Uploaded by

Aravind Aravind
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)
45 views33 pages

Containers Shyam

Docker is a platform for developing, deploying and running applications using containers. Containers allow applications to be packaged with all dependencies and run consistently regardless of environment. Key Docker commands allow users to run, stop, list and remove containers. Docker images contain the contents of containers and are built using Dockerfiles which specify build instructions through commands like FROM, RUN and CMD. Containers provide benefits like being lightweight, portable and efficient compared to traditional virtual machines.

Uploaded by

Aravind Aravind
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/ 33

Introduction to Docker

Intro and Basics of Containerization

● What is a Container?
● Containerization vs. Virtual Machine
● Docker Installation
● Main Docker Commands
● Building your own Containerized Image for Flask Application
Applications are transforming
Application Modernization

Developer Issues: ● Microservices: Break application into


● Minor code changes require full re-compile separate operations
and re-test ● 12-Factor Apps: Make the app
● Application becomes single point of failure Independently scalable, stateless, highly
● Application is difficult to scale available by design
Traditional Deployment

Early on, organizations ran applications on


physical servers.
Demerits of Traditional Deployment

• Consider multiple applications


running on one server

• There can be a time where one


application may take up entire
resource allocation

• It may result in underutilization of


resources and increase the cost
Overview of deployments
How virtualization works
Virtualization is a process whereby software is used to create an
abstraction layer over computer hardware that allows the
hardware elements of a single computer to be divided into
multiple virtual computers.
Hypervisors
A hypervisor is the software layer that coordinates VMs. It serves
as an interface between the VM and the underlying physical
hardware, ensuring that each has access to the physical
resources it needs to execute. It
Virtual Machine vs Containerization

● Containers are similar to


VMs, but they have
• VM’s are preferred as relaxed isolation
they have better properties to share the
resource utilization OS among the
• Reduce the production applications
cost and helps in
better scalability ● They are easily portable
compared to and could work on any
Traditional deployment
platform or environment

● It can automatically
allocate resources to the
nodes that are free and
saves much time
What is a container

● Containers are lightweight software packages


that contain all the dependencies required to
execute the contained software application.

● A way to package application with all necessary


dependencies and configurations
● Portable artifact ,easily shared and moved
around
● Share the same OS kernel
Before Containers

Mongo
Node js Mongo
Express Node js
Express
● Installation process was different

● OS environment.

● Many Steps were something could go wrong.

Developer Developer
After Containers

❏ Own isolated environment

❏ Packed with all needed packages


Node Container Node Container

❏ One command to install the App

❏ Run same app with two different versions


Where do containers live ?

Container Registry

Private Repositories

Public Repository for Docker (Docker Hub)


Key Benefits of Docker Containers
What is Docker

The Docker platform it provides the ability to


package and run an application in a loosely isolated
environment called a container.

https://www.docker.com/

https://hub.docker.com/
What is Docker?

Docker is popular virtualization software that helps its users in developing, deploying,
monitoring, and running applications in a Docker Container with all their dependencies.

Docker containers include all dependencies (frameworks, libraries, etc.) to run an


application in an efficient and bug-free manner.

Docker Containers have the following benefits:

● Light-weight
● Applications run in isolation
● Occupies less space
● Easily portable and highly secure
● Short boot-up time
Docker architecture
Docker Installation
● Docker currently separates its product lines into two segments.
○ Community Edition (CE), which is closed-source yet completely free, and
○ Enterprise Edition (EE), which is also closed-source and needs to be licensed on a yearly
basis
● If you are using macOS or have Windows 10 Professional installed on your laptop, it is
recommended that you install Docker for Desktop.
● Docker for Desktop doesn’t support linux. You need to install it differently.
Steps to install Docker
1. No matter what OS you're using, navigate to the Docker start page at
https://www.docker.com/get-started.
2. On the right-hand side of the loaded page, you'll find a big blue button saying Download
Desktop and Take a Tutorial. Click this button and follow the instructions.
3. You will be redirected to Docker Hub. If you don't have an account on Docker Hub yet, then
create one. It is absolutely free, but you need an account to download the software.
Otherwise, just log in.Once you're logged in, look out for the below image on the page:
Steps to install Docker
1. Click the blue Download Docker Desktop button
2. Note that if you're on a Windows PC, the blue button will say Download Docker Desktop for
Windows instead.
3. Once you have successfully installed Docker for Desktop for macOS, please open a Terminal
window and execute the following command to check whether Docker is properly installed or
not:

$ docker version
Docker main commands
● To create and a run a demo docker container in your system. Type the below
commands.
$ docker container run alpine echo "Hello World"
$ docker run -d -p 80:80 docker/getting-started
● This command contains multiple parts. First and foremost, we have the word
docker.
● This is the name of the Docker Command-Line Interface (CLI) tool, which we are
using to interact with the Docker engine that is responsible to run containers.
● Next, we have the word container, which indicates the context we are working
with. As we want to run a container, our context is the word container.
● Next is the actual command we want to execute in the given context, which is run.
Starting and Stopping Containers
● A container can be started again using the docker container start command

$ docker container start <CONTAINER_NAME>

● To stop a container, then we can do so by issuing this command

$ docker container stop <CONTAINER_NAME>

● Now, instead of using the container name, we can use the CONTAINER_ID in our
expression:

$ docker container stop <CONTAINER_ID>


Listing Docker Containers
● To find out what is currently running on our host, we can use the container ls command, as
follows

$ docker container ls

● By default, Docker outputs seven columns with the following meanings:


○ Container ID : This is the unique ID of the container. It is an SHA-256.
○ Image: This is the name of the container image from which this container is instantiated.
○ Command: This is the command that is used to run the main process in the container.
○ Created : This is the date and time when the container was created.
○ Status: This is the status of the container (created, restarting, running, removing,
paused, exited, or dead).
○ Ports: This is the list of container ports that have been mapped to the host.
○ Names: This is the name assigned to this container (multiple names are possible).
Docker Commands
● If we want to list not only the currently running containers but all containers that are defined
on our system, then we can use the command-line parameter -a or --all, as follows:
$ docker container ls -a
● This will list containers in any state, such as created, running, or exited.Sometimes, we want
to just list the IDs of all containers. For this, we have the -q parameter:
$ docker container ls -q
● You can invoke help for the list command as follows:
$ docker container ls -h
Inspecting and Running Containers

● Containers are runtime instances of an image and have a lot of associated data that
characterizes their behavior.
● To get more information about a specific container, we can use the inspect command

$ docker container inspect <CONTAINER_NAME>

● To run a docker container

$ docker container exec -t <CONTAINER_NAME> /bin/sh


Removing Containers

● The command to remove a container is as follows:

$ docker container rm <container ID>

● Another command to remove a container is the following:

$ docker container rm <container name>


Docker Images

● In Linux, everything is a file. The whole operating


system is basically a filesystem with files and folders
stored on the local disk
● An image is basically a file system with layers.
● The layers of a container image are all immutable.
● Immutable means that once generated, the layer
cannot ever be changed
● Docker Hub is a public registry for container images.
● It is a central hub ideally suited for sharing public
container images.
How to create a Docker Image
Docker Image is created using Dockerfile
Dockerfile

The specific commands you can use in a dockerfile are:

FROM, PULL, RUN, and CMD

● FROM - Creates a layer from the OS ( like parent image )


● PULL - Adds files from your Docker repository
● RUN - runs command
● CMD - Specifies what command to run within the container
● ENTRYPOINT allows specifying a command along with the parameters
● ADD command helps in copying data into a Docker image
● ENV provides default values for variables that can be accessed within the container
● EXPOSE instruction exposes a particular port with a specified protocol inside a Docker
Container.
Dockerfile
A Dockerfile is simply a text-based script of instructions that is used to create a container image.

FROM python:3.6
WORKDIR /app
ADD . /app
COPY requirements.txt /app
RUN python3 -m pip install -r requirements.txt
RUN python3 -m pip install ibm_db
RUN python3 -m pip install requests
EXPOSE 8080
CMD ["python","app.py"]
Command : docker build -t <image_name> .
Example : docker build -t hello-world .
Next docker image was created with name
For finding images of docker we use command
Command : docker image ls -a
For Delete image
Command : docker rmi <image_name>

You might also like