Search This Blog

Friday, June 27, 2025

Q11-Q15

Q11: What is Docker?
Q12: What is Docker Containerization?
Q13: What is the basic structure of Docker file. What does it do?
Q14:  What is Docker image?
Q15: What is the difference between Docker image and Docker container?

Master Stroke:
Dockerfile → builds → Docker Image → runs as → Docker Container → managed inside → Kubernetes Pod


[Docker Related Questions]
-----------------------------------------------------------------------------------------------------------------------------
Q11: What is Docker

Answer:
Docker is an open-source platform that automates the deployment, scaling, and management of applications using containers. Containers are lightweight, portable units that package an application with all its dependencies, ensuring it runs consistently across environments—whether it's your laptop, a test server, or production
-----------------------------------------------------------------------------------------------------------------------------
Q12: What is Docker Containerization?

Answer:
Containerization is the process of packaging applications and their dependencies into containers.
Unlike Virtual Machines (VMs), containers don’t need a full guest OS. They share the host’s OS kernel but run isolated processes.
This makes containers faster, lighter, and more portable compared to VMs.
-----------------------------------------------------------------------------------------------------------------------------
Q13: What is the basic structure of Docker file. What does it do?

Answer: 

A Dockerfile is a text file that contains instructions for building a Docker image. It’s like a recipe for creating containers. 
So, a Dockerfile is essentially the blueprint for creating a Docker image.

A Dockerfile is a text file that contains a series of instructions on how to build a Docker image.

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY . .
RUN dotnet restore "MyMicroservice/MyMicroservice.csproj"

WORKDIR "/src/MyMicroservice"
RUN dotnet build "MyMicroservice.csproj" -c Release -o /app/build
RUN dotnet publish "MyMicroservice.csproj" -c Release -o /app/publish

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final
WORKDIR /app
COPY --from=build /app/publish .

EXPOSE 8080
ENTRYPOINT ["dotnet", "MyMicroservice.dll"]


# 1. Uses the official .NET 8 SDK image to compile and build the application. This image contains the compiler, Build tools, Restore tools. Everything needed to build and publish your application
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build

# 2. Sets the working directory inside the container to /src.
WORKDIR /src

# 3. Copy project files and all the source code into the container. Restores NuGet packages. Prepares all dependencies needed for the build.
COPY . .
RUN dotnet restore "MyMicroservice/MyMicroservice.csproj"

# 4. Changes the working directory to the project folder. Builds the application in Release mode.
WORKDIR "/src/MyMicroservice"
RUN dotnet build "MyMicroservice.csproj" -c Release -o /app/build

# 5. Publish the app. Prepares the app for runtime by including only necessary files.
RUN dotnet publish "MyMicroservice.csproj" -c Release -o /app/publish

# 6. Use the runtime image for the final container. Uses a smaller runtime-only image. Its just a core runtime image. Not like we have in Step 1, which is much bigger. 
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final
WORKDIR /app
COPY --from=build /app/publish .

# 7. Expose the port your service listens on
EXPOSE 8080

# 8. Set the entry point. Defines the command to run when the container starts.
ENTRYPOINT ["dotnet", "MyMicroservice.dll"]

-------------------------------------------------------------------------------------------------------------------------------
Q14:  What is Docker image?

Answer:
A Docker image is a snapshot of a container's file system and configuration. It’s built from a Dockerfile and contains everything needed to run an app:
Code, Runtime, Libraries, Environment variables
-----------------------------------------------------------------------------------------------------------------------------
Q15: What is the difference between Docker image and Docker container?

Answer:
Docker Image - 
1- Blueprint for creating containers
2. Created from Docker file. 
3. Its a static instance/snapshot of your application/code. 

Docker Containers: 
1- They are created from Image. They are running instance of an image. 
2. Created from an image. 
3. Running instance of an image. 

Points:
A single image can have multiple containers running on it. 
Image is like a class in dotnet while containers are like object of that class. 

-----------------------------------------------------------------------------------------------------------------------------

No comments:

Post a Comment

Q31-Q35

Q31: What is pods and how it is related to Docker images and Docker containers? Q32: What is the use of Compose Docker file? Q33. What are t...