Day-2:Docker Zero To Hero Bangla Course (Module-2- Multistage Docker Images & Containers)

 


Docker Architecture


 

Docker Daemon (dockerd): At the core of Docker's architecture is the Docker daemon, dockerd. It runs on the host machine and manages Docker objects such as images, containers, networks, and volumes. The daemon listens for Docker API requests and executes them. It's responsible for building, running, and distributing Docker containers.

Docker Client: The Docker client is a command-line interface (CLI) tool that allows users to interact with the Docker daemon via the Docker Remote API. Users issue commands to the Docker client, which then communicates with the Docker daemon to perform the requested actions. The client can run on the same machine as the daemon or on a remote machine that connects to the daemon over a network.

Docker Registries: Docker registries are repositories for Docker images. They store and distribute Docker images, allowing users to share and collaborate on containerized applications. Docker Hub is the default public registry provided by Docker, which hosts a vast collection of pre-built images for popular software stacks. Organizations can also set up private registries to store proprietary or sensitive images within their infrastructure.

 

Multi Stage Dockerfile

Multi-stage Dockerfile is an essential feature provided by Docker that allows developers to create more efficient and smaller Docker images, resulting in faster builds, reduced image sizes, and improved security. The importance of using multi-stage Dockerfiles can be summarized as follows:

  1. Reduced Image Size: Multi-stage builds enable developers to build images with only the necessary dependencies and artifacts needed for runtime. By using separate stages in the Dockerfile, you can build your application in one stage and then copy only the compiled binary or artifacts into a new stage. This approach helps to minimize the final image size by eliminating unnecessary build-time dependencies and intermediate files, resulting in smaller and more lightweight images.

  2. Faster Build Times: With multi-stage builds, Docker can execute multiple build stages concurrently, optimizing the build process and reducing overall build times. By separating the build environment from the runtime environment, you can take advantage of caching mechanisms provided by Docker. This means that subsequent builds only need to rebuild the stages that have changed, resulting in faster iterative development cycles and quicker deployment of updates.

  3. Improved Security: Multi-stage builds promote better security practices by reducing the attack surface of Docker images. By segregating the build environment from the runtime environment, you can ensure that only the necessary dependencies and runtime libraries are included in the final image. This helps to mitigate security vulnerabilities and potential exploits that may exist in the development and build tools used during the build process.

  4. Simplified Build Pipeline: Multi-stage Dockerfiles simplify the build pipeline by encapsulating the entire build process within a single Dockerfile. This makes it easier to manage and maintain the build process, as all the necessary steps for building, testing, and packaging the application are defined in one place. Additionally, multi-stage builds make it easier to share and collaborate on Dockerfiles, as they encapsulate best practices and standardize the build process across different environments.

  5. Portability and Consistency: Multi-stage Dockerfiles promote portability and consistency across different deployment environments. By defining the build environment and runtime environment separately, you can ensure that the application behaves consistently across different platforms and deployment scenarios. This simplifies the process of deploying applications to production, testing, and staging environments, reducing the risk of compatibility issues and runtime errors.

 

Clone the Repo: git clone https://github.com/shawon100/Angular-CRUD

Go to Angular-CRUD folder

cd Angular-CRUD

Remove existing Dockerfile and Create a New Dockerfile

### STAGE 1: Build ###
FROM node:10-alpine AS build
WORKDIR /usr/src/app
COPY . /usr/src/app
RUN npm install
RUN npm run build

### STAGE 2: RUN ###
FROM nginx:1.17.1-alpine
ADD https://raw.githubusercontent.com/shawon100/Angular-CRUD/master/nginx.conf /etc/nginx/nginx.conf
COPY --from=build /usr/src/app/dist/crud /usr/share/nginx/html

 Build the Docker Image

 docker build -t angularcrud .

 Run the Docker Container

 docker run -d -p 4200:80 --name angularapp angularcrud

 Access the application

 http://localhost:4200


Video Tutorial






 


 

 

Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment