![Mission Specialist Mission Specialist](/html/rank_icons/RH_SERV_005534_01_MECH_Rank_Specialist_16x16@2x.png)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- 9,308 Views
Optimize container image in Openshift
![Community Manager Community Manager](/i/rank_icons/admin.gif)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- 6,759 Views
Hi @Markus77 ,
some of the ways you can do that :
1. By using a lightweight base image as the foundation of your conatiner image.
2. Reduce the number of layers in your container image.
3. You can use build cache strategy which will help the build process go faster.
4. You can use a compiled language and can use reduce the memory the app uses.
![Flight Engineer Flight Engineer](/html/rank_icons/RH_SERV_005534_01_MECH_Rank_Engineer_16x16@2x.png)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- 6,702 Views
Hi.. @Markus77 , You can do things like:
- Using a base image that is as small as possible.
- Remove unused files from your image (you can use a tool like "docker image prune" to remove any unused files from your image.)
- Implement resource limits.
- Optimize image caching:
- Use a registry that is optimized for performance.
All this thing you can google it.
I hope this is helpful for you.
![Flight Engineer Flight Engineer](/html/rank_icons/RH_SERV_005534_01_MECH_Rank_Engineer_16x16@2x.png)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- 6,671 Views
1 Use image like: registry.access.redhat.com/ubi8/ubi-minimal:latest because the UBI images allow you to share container images with others. Four UBI images are offered: micro, minimal, standard, and init. Pre-build language runtime images and YUM repositories are available to build your applications.
2 Implement resource limits
FROM # registry.access.redhat.com/ubi8/ubi-minimal:latest
WORKDIR # /app path
COPY . . # Copy over all files in the current directory
RUN npm install # Install dependencies
RUN npm build # Run build
![Mission Specialist Mission Specialist](/html/rank_icons/RH_SERV_005534_01_MECH_Rank_Specialist_16x16@2x.png)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- 6,669 Views
1) Reduce number of Layers
2) consolidate mutiple/related RUN /COPY commands together using "&&"
3) Use purposebuilt base image from a trusted registry such as redhat container registry.
![Mission Specialist Mission Specialist](/html/rank_icons/RH_SERV_005534_01_MECH_Rank_Specialist_16x16@2x.png)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- 6,641 Views
@Markus77 As all the other users have said before, the best way to reduce a container image size is by reducing the number of layers.
Here is an example of an image with the same source files and with significant less layers:
![Mission Specialist Mission Specialist](/html/rank_icons/RH_SERV_005534_01_MECH_Rank_Specialist_16x16@2x.png)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- 4,354 Views
How to reduce layers? Are there any steps provided?
![Mission Specialist Mission Specialist](/html/rank_icons/RH_SERV_005534_01_MECH_Rank_Specialist_16x16@2x.png)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- 6,628 Views
Good recommendations here : https://docs.openshift.com/container-platform/4.13/openshift_images/create-images.html
![Mission Specialist Mission Specialist](/html/rank_icons/RH_SERV_005534_01_MECH_Rank_Specialist_16x16@2x.png)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- 6,625 Views
Make sure to use a base image that is closely aligned with needs of your application. All the previous replies would help you with keeping your image footprint small.
With Openshift you can refer to a image with its image stream(alias), that way you still refer to the same image in your registry and not be concerned about updates to your image that would cause a problem for your apps. Of course, you would want to pay attention to security and vulnerability that the later updates fix for your base image(s).
Hope this helps!
![Mission Specialist Mission Specialist](/html/rank_icons/RH_SERV_005534_01_MECH_Rank_Specialist_16x16@2x.png)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- 6,523 Views
Good morning, Dear @Markus77
Optimizing a container image in OpenShift is an important task to improve the performance and efficiency of your applications.
Here are some tips on how to do it:
Use a suitable base image: it is important to choose a base image that is suitable for your application. A smaller and lighter base image can improve performance and reduce loading time.
Minimize image layers: The fewer layers the image has, the faster it will load. You can reduce the number of layers by removing unnecessary files and combining commands into a single layer.
Use the layer cache: OpenShift uses a layer cache to speed up image construction. Make sure your images are configured to use the layer cache.
Use image optimization tools: There are several tools available to optimize container images, such as Docker Slim and Kaniko. These tools can reduce image size and improve performance.
Use cached build strategies: If you are building container images from source code, you can use cached build strategies to reduce build time. This involves caching the results of previous builds to avoid having to recompile all the code each time.
I hope you find these tips useful for optimizing your container images in OpenShift - good luck!