Uploaded by gautamshri83

ACFrOgANSD55S3JbRJ762xUgjbM4kmM vDkJvhPIku5KDaFU6vtN3WVcolhtPdmY7vABnQV2gxvvMkEwNIA4PGFQu3re6t9bfupkqeo-PMIAne585mjAU3e7lQ0Er2jDa6Cp6V9nmE13Zr9GKqXX3kvf8ZE34RnKM7 M6YhSzA==

advertisement
Name of Student: Rohit Ganesh Mehta
Roll Number: 32
Lab Assignment Number: 8
Title of Assignment : To understand Docker Architecture and
Container Life Cycle, install Docker and execute docker commands
to manage images and interact with containers.
DOP: 17-03-2024
DOS: 22-03-2024
CO
Mapped: CO6
Signature:
PO
Mapped: PO3,
PO5, PO7, PO12
PSO1, PSO2
Marks:
Name: Rohit Ganesh Mehta
FYMCA/A
Roll No:32
ASSIGNMENT NO: 6
Aim: To understand Docker Architecture and Container Life Cycle,
install Docker and execute docker commands to manage images and
interact with containers.
Theory:
Docker is a container management service. The keywords of Docker are develop,
ship and run anywhere. The whole idea of Docker is for developers to easily
develop applications, ship them into containers which can then be deployed
anywhere.
The initial release of Docker was in March 2013 and since then, it has become the
buzzword for modern world development, especially in the face of Agile-based
projects.
An image is a read-only template with instructions for creating a Docker
container. A docker image is described in text file called a Dockerfile, which has a
simple, well-defined syntax. An image does not have states and never changes.
Docker Engine provides the core Docker technology that enables images and
containers.
Docker container is a running instance of an image. You can use Command Line
Interface (CLI) commands to run, start, stop, move, or delete a container. You can
also provide configuration for the network and environment variables. Docker
container is an isolated and secure application platform, but it can share and
access to resources running in a different host or container.
What is a container?
A container is an isolated environment for your code. This means that a container
has no knowledge of your operating system, or your files. It runs on the
environment provided to you by Docker Desktop. Containers have everything that
your code needs in order to run, down to a base operating system.
Name: Rohit Ganesh Mehta
FYMCA/A
Roll No:32
It allows developers to package up the application with all its libraries and
dependencies, and ship it as a single package. The advantage of using a docker
container is that you don't need to allocate any RAM and disk space for the
applications. It automatically generates storage and space according to the
application requirement.
Docker Architecture
1. Docker Client
Name: Rohit Ganesh Mehta
FYMCA/A
Roll No:32
Docker client uses commands and REST APIs to communicate with the Docker
Daemon (Server). When a client runs any docker command on the docker client
terminal, the client terminal sends these docker commands to the Docker
daemon. Docker daemon receives these commands from the docker client in the
form of command and REST API's request.
Docker Client uses Command Line Interface (CLI) to run the following commands docker build
docker pull
docker run
2. Docker Host
Docker Host is used to provide an environment to execute and run applications. It
contains the docker daemon, images, containers, networks, and storage.
3. Docker Registry
Docker Registry manages and stores the Docker images.
There are two types of registries in the Docker Pubic Registry - Public Registry is also called as Docker hub.
Private Registry - It is used to share images within the enterprise.
Docker is popular because of the following:
1. Portability.
2. Reproducibility.
3. Efficiency.
4. Scalability.
What is Dockerfile?
The Dockerfile uses DSL (Domain Specific Language) and contains instructions
for generating a Docker image. Dockerfile will define the processes to quickly
produce an image. While creating your application, you should create a
Dockerfile in order since the Docker daemon runs all of the instructions from top
to bottom.
Name: Rohit Ganesh Mehta
FYMCA/A
Roll No:32
It is a text document that contains necessary commands which on
execution help assemble a Docker Image.
● Docker image is created using a Docker file.
What is Docker Hub?
Docker Hub is a repository service and it is a cloud-based service where people
push their Docker Container Images and also pull the Docker Container Images
from the Docker Hub anytime or anywhere via the internet. Generally it makes it
easy to find and reuse images. It provides features such as you can push your
images as private or public registry where you can store b in and share Docker
images
●
Download and install Docker Desktop from
https://www.docker.com/products/docker-desktop/
Download required base images like node,php etc.
Pull image and run container
Search for node js in docker desktop/docker hub
Open cmd-> docker pull node or use the pull option given with node image
You can now see the node image within images tab in docker desktop
Now create a container using the command
docker run -it node /bin/bash
Go to containers tab -> run the container. Try to run some commands on the
node terminal
Eg. node -v
Console.log(10+20) etc,
Running a simple app in docker container
Open vs code
Create package.json file , install express
Create a index.js file
Name: Rohit Ganesh Mehta
FYMCA/A
Roll No:32
const express= require(“express”);
const app=express();
app.get(“/”,(req,res)=>{
res.json([
{
id:1,
name:”abc”,
age:26
},
{
id:2,
name:”www”,
age:23
},
])
});
app.listen(5500,()=>{
console.log(“app running in port 5500”);
}
Run the application .
Now let us create image of the application which we have created
Create a empty file with the name dockerfile and also install the docker
extension in VS code editor
Open the dockerfile-> write the code to build and run the code
FROM node:latest
Name: Rohit Ganesh Mehta
FYMCA/A
COPY . .
RUN npm install
EXPOSE 5500
CMD[ “node”, “index.js”]
Now in terminal execute the foll. Command
Docker build -t basic-app .
Roll No:32
Name: Rohit Ganesh Mehta
Docker version
Docker search
Docker pull
Docker run
Docker ps
FYMCA/A
Roll No:32
Name: Rohit Ganesh Mehta
FYMCA/A
Roll No:32
Docker stop
Docker restart
Docker kill
Docker Logout
Conclusion :
We have understood Docker Architecture and Container Life
Cycle, install Docker and execute docker commands to manage
images and interact with containers.
Download