Showing posts with label docker multistage. Show all posts
Showing posts with label docker multistage. Show all posts

Tuesday, July 9, 2024

Confused about Multi architecture ?


Are you confused 😕 about Multi architecture in Docker  ?  Just think of Shoes 👞.... yeah shoes and how you use them .. 

  • You have a shoe closet with multiple shoe types (e.g., running shoes, hiking boots, dress shoes)
  • Manual selection of the right shoe type for each activity
  • Appropriate footwear for various terrains and occasions
  • Central storage for all shoe types

Similarly Docker Multi-Architecture Images has 

  • One image tag, multiple CPU architectures (e.g., x86, ARM, PowerPC)
  • Automatic selection of the right architecture by the Docker runtime
  • Same application runs across diverse hardware platforms
  • Single management point for multiple architecture versions

Docker can still run anywhere right ?

Yes ,you can use the same shoe every where but not ideal right . Similarly traditional images are built for a specific architecture (e.g., x86-64 or ARM64). Multi-architecture images contain multiple versions of the same image, each built for a different architecture, bundled together under a single tag.

How does it do it ?

Multi-architecture images use manifest lists (also called fat manifests) to specify which image version should be used for each supported architecture. When a client pulls a multi-architecture image, Docker automatically selects the appropriate version based on the host system's architecture

Build is complicated ?

Yes kind of ,Multi-architecture images require separate builds for each target architecture, often using tools like Docker Buildx . Here is a example it not that difficult 

Github

Yeah , but like why .. What's the main advantage ?

Just like using the right shoe will give you the best performance and utilization . Multi-architecture images allow for more efficient use of resources by supporting diverse CPU architectures without maintaining separate images . This is especially realized in the cloud by using the correct architecture-specific image, you can achieve better resource utilization and potentially reduce costs, especially in cloud environments with diverse instance types 

Containerization Github List  ->   Github Containers

Monday, July 8, 2024

Difference between Multistage vs Docker-in-Docker

Developers often confuse two important Docker concepts: multi-stage builds and Docker-in-Docker (DinD). While both involve Docker and are used in build processes, they serve different purposes and are implemented in distinct ways. Let's clarify these concepts with descriptions and examples


Multistage

Multistage build is for the developers building the docker image to use multiple stages . The main reason is to minimize the image size and practice better security as it minimizes the attack surface . There are usually multiple FROM statements for each of the stages in the build . 

Here is an example of the nodejs application built using this approach . Go application will be a better example as only the binaries will be copied to the final image , I am using nodejs for simplicity 

Github Docker Multistage




Docker-in-Docker

Docker-in-Docker refers to running a Docker daemon inside a Docker container . Its mainly used by CI/CD pipelines to build container images . This doesn't necessarily improve security , in-fact as the daemon needs to run as root it has to be run with the privileged flag ( may be the only place where this is okay ). 

It can be also used for Integration and Sanity testing as the main Docker container acts as a platform for all the other containers . You can use tools like Docker Compose to bring up multiple containers that represent different services in your application stack and run the tests . After tests are complete, you can easily tear down the entire environment, ensuring a clean slate for the next test run and improving reproducibility

here is an nodejs example demonstrating this

Github Docker-in-Docker

Containerization Github List  ->   Github Containers

Should You Use Containers with Serverless Implementations?

Serverless implementations are usually Cloud Deployment-specific, AWS Lambda being the most popular implementation. However, there are some ...