Improving the image build

Search for a command to run...

No comments yet. Be the first to comment.
Introduction Argo Workflows is an open-source workflow orchestration tool for Kubernetes. In this tutorial, we will walk through the steps to install Argo Workflows on a Kubernetes cluster and access its server UI. Step 1: Check Current Context Befor...

The Azure CLI is a powerful tool for managing and automating tasks in Azure. To use the Azure CLI, you need to log in to your Azure account. In this blog, we will go over the different methods you can use to log in to Azure using the Azure CLI. Log i...

Connecting to an Azure VM from windows can be a bit tricky and you may get errors like WARNING: UNPROTECTED PRIVATE KEY FILE! Permissions for ' ' are too open, It is required that your private key files are NOT accessible by others This private key w...

A methodology where all the configurational and/or infrastructure codes are set up in a separate single repository is known as GitOps. This suits tools like Ansible, Terraform and Kubernetes, where they do require separate files for their configurati...

Straight to the point, there are tons of things to ask in JS, but these are a few of them which can be a quick refresher. Event loop, Single-threaded programming language - Explain, Asynchronous and synchronous, Promises and callbacks, "This" ke...

Peace to you all , Here is the Link to my previous blogs, Where I have posted about Docker, Containers and DevOps.
This is Day 9 of documenting my DevOps journey .
This blog focuses on Improving the docker image build.
As we know , building images follows a layered approach , each instruction in a dockerfile is built as a layer . The result artifact of the previous layer will be used in the next layer.
Let us take the last example where we containerized an angular app .
The Dockerfile of the angular app can be found below.
FROM node:lts-alpine as build
WORKDIR /usr/local/app
COPY ./ /usr/local/app/
RUN npm install
RUN npm run build
FROM nginx
COPY --from=build /usr/local/app/dist/ang /usr/share/nginx/html
EXPOSE 80
We can say, since it is following a layered approach ,Each instruction will take specific time to complete.
Each and every time an image is built with this dockerfile , node modules are copied to the container . This is not the standard way to do it .
Copying the node modules is not necessary since npm install , installs node modules, in can be done through that command and there will be no need to copy the node modules from the host.
.dockerignore is the file which provides solution for this problem , As like gitignore , this can be set according to our requirements.
Before starting the build , docker looks for .dockerignore files . The name of the files mentioned on dockerignore will be ignored from the docker build.
For example ,
We don’t want the node modules of the angular app and so we can reference the folder in the .dockerignore file like below.
**/node_modules
Here the ** tells the docker to take all the subfolders of the folder mentioned.
This way , while building , the node_modules won’t be copied and the process can be simplified.
But that doesn’t stop there.
Package.json helps in installing the node modules , So we should not add it in dockerignore.
We can just look at the project and check what we need, to add to the project and what should not be added .
Dockerfile and dockerignore as we can say , are not necessary for the app to run , it is just for creating an image and it will be taken automatically from the current folder while building .
So we don’t necessarily need to copy those files to the container and so we can pass those names in dockerignore along with node_modules.
There are many extensions , tools which auto-generate dockerignore , but at the core , we must also know what should be on the container and what does not need to be .
There are certain standards, where if it is an angular app, we can definitely ignore some files for sure and the rest as we need can be added one by one. App-specific dockerignore files are also available for use and can add more in the list if required.
Now building the image with dockerignore , Optimizes and improves the build.
Dockerignore is a great way for leaving out unwanted files and improve the image build.
We left those files which are not required on building an image and this way improving the image build.
Okay . So hold on, stay with me as we get to know docker more and DevOps even more.
Okay Then , Will get back Tomorrow with more!
Peace be upon you!