You are on page 1of 8

01-: What is Docker?

A-: Docker is a software platform that allows you to build, test, and deploy
applications quickly. Docker packages software into
standardized units called containers that have everything the software needs
to run including libraries, system tools, code,
and runtime. Using Docker, you can quickly deploy and scale applications
into any environment and know your code will run.

02-: What is Docker Images?


A-: In one line we can say "an image is a template of your complete project" just
like an image of windows operating system.
• It is a kind of ready-to-use software read-only template
• Images is made with source codes, libraries, external dependencies, and
tools.
• Images can not be updated.
• If you want to make change in image you have to create new image.
• Images can not run directly.

For Example - If we are making a front-end React application then the image
should contains below mentioned items:

> Application tools and Libraries.


• Node js setup
• React setup
• Code of application
• Dependencies
• Any other supporting tool
• Docker file too
• We can say that image is a template of project.

03-: What is Docker Container?


A-: Container is a runnable instance of an image.

• The container is a process that runs applications with images


• Container is an isolated process.
• Means Container run independently on computer

Container Container
Container

App 1 App
2 App 3
Bins/Libs Bins/Libs
Bins/Libs

Node 17 Node 18
Node 19

A container is a standard unit of software that packages up code and all its
dependencies so the application runs quickly
and reliably from one computing environment to another. A Docker container
image is a lightweight, standalone, executable
package of software that includes everything needed to run an application:
code, runtime, system tools, system libraries
and settings.

Container images become containers at runtime and in the case of Docker


containers – images become containers when they run
on Docker Engine. Available for both Linux and Windows-based applications,
containerized software will always run the same,
regardless of the infrastructure. Containers isolate software from its
environment and ensure that it works uniformly despite
differences for instance between development and staging.

04-: What is Docker hub?


A-: 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. It provides features such as you can push
your images as private or public. Mainly DevOps team uses the Docker Hub. It
is an open-source tool and freely available for all
operating systems. It is like storage where we store the images and pull the
images when it is required. When a person wants to
push/pull images from the Docker Hub they must have a basic knowledge of
Docker. Let us discuss the requirements of the Docker tool.

Docker is a tool nowadays enterprises adopting rapidly day by day. When a


Developer team wants to share the project with all
dependencies for testing then the developer can push their code on Docker
Hub with all dependencies. Firstly create the Images and
push the Image on Docker Hub. After that, the testing team will pull the
same image from the Docker Hub eliminating the need for any
type of file, software, or plugins for running the Image because the
Developer team shares the image with all dependencies.

Docker Hub Features::

• Storage, management, and sharing of images with others are made simple via
Docker Hub.
• Docker Hub runs the necessary security checks on our images and generates
a full report on any security flaws.
• Docker Hub can automate the processes like Continuous deployment and
Continuous testing by triggering the Webhooks when the new
image is pushed into Docker Hub.
• With the help of Docker Hub, we can manage the permission for the users,
teams, and organizations.
• We can integrate Docker Hub into our tools like GitHub, Jenkins which
makes workflows easy

Advantages of Docker Hub::

• Docker Container Images are light in weight.


• We can push the images within a minute and with help of a command.
• It is a secure method and also provides a feature like pushing the private
image or public image.
• Docker hub plays a very important role in industries as it becomes more
popular day by day and it acts as a bridge between the
developer team and the testing team.
• If a person wants to share their code, software any type of file for
public use, you can just make the images public on the docker hub.

05-: What key features are included in Docker Hub?


A-: Following are few of the features that are included in Docker Hub:

• Repositories: It contains the Push and Pull process for container images.
• Teams and Organizations: It allows access to developer/user to private
repositories of container images.
• Docker Official Images: It Pulls and uses high-standard quality container
images rendered by Docker.
• Docker Verified Publisher Images: It Pulls and uses high-standard quality
container images rendered by outside vendors.
• Builds: Automatically build container images from GitHub and Bitbucket and
push them to Docker Hub.
• Webhooks: Trigger actions after a successful push to a repository to
integrate Docker Hub with other services.
• Docker implements a Docker Hub CLI tool that is presently experimental and
an API (Micro-service) that enables you to communicate with
Docker Hub. You can browse the Docker Hub API documentation to explore the
supported endpoints.

06-: What administrative tasks can I perform in Docker Hub?


A-: We can perform few of the following tasks in Docker Hub:

• Create and manage teams and organizations


• Create a company
• Enforce sign in
• Set up SSO and SCIM
• Use Group mapping
• Carry out domain audits
• Use Image Access Management to control developers' access to certain types
of images
• Turn on Registry Access Management

07-: What is Docker Desktop?


A-: Docker Desktop is secure, out-of-the-box containerization software offering
developers and teams a robust, hybrid toolkit to build, share,
and run applications anywhere.

08-: What is Base Image or Parent Image?


A-: Suppose we are making a front-end React then the Docker Image should contains
below mentioned items:

> Application tools and Libraries.


• Node js setup
• React setup
• Code of application
• Dependencies
• Any other supporting tool
• Docker file tooif we have for react application we need npmThose images
with the help of which we will

It means the Docker image of React application is dependent on some other


images (like Node js image, React image etc).
These dependent images are termed as Base or Parent image.

Builds Run
Docker File -----> Docker Image -----> Docker Container
|
|
Layer C
Layer B
Layer A
Base Image

09-: Steps to
A-: Following are the steps to ::
• Download Node Image from the docker hub.
• Make a container for node js.
• Run Node js container.
• Write Node js Code inside conatiner.

10-: Command to pull images from Docker hub .


A-: Command to pull images from Docker hub - "docker pull node"

11-: Command to run images after pulling it from Docker hub.


A-: Command to run images - "docker run -it node /bin/bash"

12-: Command to create Docker File.


A-: Command to create Docker File - "touch dockerfile"

Note:- Docker file created should not have any file extension.

13-: Steps to create Docker image.


A-: Suppose we are going to create a Docker image for a Node.js application then
we have to do following steps to create a Docker image.
If we are using VS code tool for coding then:

Step 1: Create a Docker file with tbe name "dockerfile" in the project
directory (note: docker file should not have any extension).
Docker file can be created from terminal using command "touch
dockerfile" or you can create it without command by directly creating inside the
project
directory.

Step 2: Now you have to install Docker in the project. Here we have two
option to do so. First: The moment you create the Docker file
VS code will ask to install Docker with a link. Second: Search
for microsoft extention of the Docker and install it. You can
choose any option to install the Docker.

Step 3: Write the below mentioned code/script into the Docker file created
in Step 1.

FROM baseImage
FROM node: latest
COPY source dest .
COPY . .
RUN command ==========>
RUN npm install
EXPOSE port
EXPOSE 5500
CMD ["executable"]
CMD ["node","index.js"]

Step 4: Execute the code/script created in Step 3 using below command from
terminal.

docker build -t <image name to be created> <image path>


=====> docker build -t basic-app .

14-: Random port or no port for container?


A-: -No port: To run the image in container we have to configure the port. Now if
run the image without configuring the port then the
application will not run if we browse the url. This is called no port.
-Random port: To run the image in container we have to configure the port.
Now if we configure the port no. field with "0" value then the
application will be assigned a random port no. to run the application. This
is called random port. You can find the port no. assigned from
port no. column in the docker container screen.

15-: What is .dockerignore file?


A-: .dockerignore file is a file that is used to ignore those files/folder to take
part in the docker image creation.So if we want to skip any
files/folder to be added in the docker image then just mention those
files/folder name in the ".dockerignore file"

16-: How to skip any partcular file extention to be added in the docker image
creation?
A-: Just mentioned the extention of the file in the .dockerignore file.

for example: if we want to skip "text' files to be added in the docker image
then just add "*.txt" in the dockerignore file.

17-: Command to check list of image and their associated container.


A-: docker ps -a

18-: Delete command for docker image and docker container


A-: -Delete docker image:

> When image status is "Unused" (delete normally)

docker image rm <image-name> docker image rm


node_image_1

> When image status is "In Use" (delete forcefully)

docker image rm <image-name> -f docker image rm


node_image_2 -f

-Delete docker container:

> When container status is "Exited" (delete normally)

docker container rm <container-name> docker


container rm node_container_1

> When container status is "Running" (delete forcefully)

docker container rm <container-name> -f docker


container rm node_container_2 -f

19-: Command to delete all docker images and all docker containers.
A-: Command to delete all docker images and all docker containers is:

docker system prune -a

20-: Create docker image with version.

A-: >This will create docker image having version as "latest"

docker build -t <image name to be created> <image path> =====>


docker build -t basic-app .
>This will create docker image having version as "v2"

docker build -t <image name to be created>:v2 <image path> =====>


docker build -t basic-app:v2 .

21-: Command to run docker images with version no.


A-: Command to run docker images with version no. is:

docker run --name basic-app-container-v2 -p 5500:5500 basic-app:v2

22-: What is docker volume?


A-:

23-: Steps to add docker volume.


A-: Following are the steps to add docker volume to the application:

Step 1: Install "nodemon" using below command.

npm i nodemon

Step 2: Add command under script section in package.json file to run the
application using nodemon like below:

"scripts": {
"test": "react-scripts test",
"eject": "react-scripts eject",
...
...
...,
"dev": "nodemon index.js"
},

Step 3: Now run the below command from terminal.

npm run dev

24-: Update the script mentioned in Step 3 of point 13 in the docker file to add
the install command for "nodemon"

A-: FROM baseImage


FROM node: latest
RUN command
RUN npm install -g nodemon
WORKDIR /the/workdir/path
WORKDIR /app
COPY source dest .
COPY . .
RUN command ==========> RUN
npm install
EXPOSE port
EXPOSE 5500
CMD ["executable"]
CMD ["npm","run","dev"]

Now once the docker file is updated we create the docker images and run the
docker container using below command:

>To create docker image - docker build -t basic-app .


>To run the docker container - docker run --name basic-conatiner -p
5500:5500 --rm -v /Users/anilsidhu/Desktop/basic-app:/app basic-app

25-: What is compose file and what is its use?


A-: Compose file is a file...

Steps to create and run compose file:

Step 1: Create a compose file with tbe name "compose.yaml" in the project
directory directly.

Step 2: Add the below script into the compose file created:

services:
img:
build:
container_name: basic-container
ports:
5500:5500

Step 3: Run the below commnd from the terminal:

docker compose up

This command will create the docker image and run the container also.

26-: Share image on Docker hub


A-: Steps to share image on Docker hub:

Step 1: Create an account on "hub.docker.com/signup" and login.

Step 2: After login, create a repository by clicking on "Create repository"


button and give a specific name to the repository like "node-app-1"
For visibility you can select public/private as per your
reqirement. Here you are going to share image so select "public" option.

Step 3: Now create the Docker image in your local machine with the command

"docker build -t <docker hub user name>/<app name> ."


===> docker build -t praveen/node-app-1 .

Step 4: Login into Docker hub account using below mentioned command:

docker login

It will open a popup to enter username/password or will


automatically login if you have already login from the browser.

Step 5: Push the image to Docker hub repository using below mentioned
command:

docker push praveen/node-app-1

Step 6: To pull the image from the Docker hub:

docker pull praveen/node-app-1


27-: Share image on Docker hub to make it live
A-: Steps to share image on Docker hub to make it live:

Step 1: Create an account on "hub.docker.com/signup" and login.

Step 2: After login, create a repository by clicking on "Create repository"


button and give a specific name to the repository like "node-demo-app"
For visibility you can select public/private as per your
reqirement. Here you are going to share image so select "public" option.

Step 3: Now create the Docker image in your local machine with the command
(note: here we have to mention the os name also to identify for which os
we are creating the image

docker buildx build-platform linux/amd64 -t praveen/node-demo-


app .

Step 4: Login into Docker hub account using below mentioned command:

docker login

It will open a popup to enter username/password or will


automatically login if you have already login from the browser.

Step 5: Push the image to Docker hub repository using below mentioned
command:

docker push praveen/node-demo-app

Step 6: Now open "https://labs.play-with-docker.com/" and sign in. Click on


"Add new instance" to create a new instance.

Step 7: Once the new instance is created, then pull the image from the
Docker hub:

docker pull praveen/node-demo-app

Step 8: Now run the Docker image using below mentioned command

docker run -p 5500:5500 praveen/node-demo-app

You can click on the port no. link displayed on top of the
screen to see your application in the browser.

You might also like