Recently, I have been started to working on docker and building them.I just had this doubt how we will we find the appropriate base image
Please clarify me how one can choose right based image for any docker file. I have seen different based image for different 8mages
2
Answers
The base image is a starting point for your Docker image. You can choose this depending on:
If you are running Python code, you can use an image with Python pre-installed. Although you can start with a base Linux image and install Python in your Dockerfile, it would take you longer to build.
If you want to deploy a MySQL instance, then you can use a base image that comes pre-installed with MySQL.
It is always better to choose the most lightweight image possible for your usecase to avoid bloating your image. For most of my projects I would prefer using Alpine which is the lightweight version of Linux.
Choosing a right based image for any docker file will totally depends on your requirements and usage, Moreover you can consider the following factors, Otherwise it can impact the size, security, and performance of your Docker image :
Source– The first step towards achieving a secure image is to choose the right base image. When choosing an image, ensure it’s built from a trusted source and keep it small.
Updates– When selecting a base image for our Docker image, it’s important to choose one that is well-maintained, trusted, and regularly updated. The official Docker images on Docker Hub are a good place to start, as they are maintained by the Docker team and undergo regular security scans and updates.
Language Choice– This is especially useful for the environment of dynamic languages – like Python or NodeJS.
Instead of getting started from a clean slate, and having to figure out how to install the $LANGUAGE version you need, you can use well-thought-out base images for the environment you need.
Minimal– When building your own image from a Dockerfile, Ensure you choose a minimal base image that matches your requirements. A smaller base image not only offers portability and fast downloads, but also shrinks the size of your image and minimizes the number of vulnerabilities introduced through the dependencies.
You can read more about this here in the article Choosing a base image for your docker file.