cancel
Showing results for 
Search instead for 
Did you mean: 
Markus77
Mission Specialist
Mission Specialist
  • 7,920 Views

Optimize container image in Openshift

Hi everyone, how can I optimize a container image in openshift?

Labels (1)
14 Replies
Chetan_Tiwary_
Community Manager
Community Manager
  • 5,667 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.

Tags (2)
Ridwan_G4
Flight Engineer
Flight Engineer
  • 5,610 Views

Hi.. @Markus77 , You can do things like:

  1. Using a base image that is as small as possible.
  2. Remove unused files from your image (you can use a tool like "docker image prune" to remove any unused files from your image.)
  3. Implement resource limits.
  4. Optimize image caching:
  5. Use a registry that is optimized for performance.

All this thing you can google it.

I hope this is helpful for you.

Psehgaf
Flight Engineer
Flight Engineer
  • 5,579 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

• ╚╬╦╬Psehgaft╬╦╬╝ ◦
0 Kudos
JohnsonPK
Mission Specialist
Mission Specialist
  • 5,577 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.

0 Kudos
AlexNisulescu
Mission Specialist
Mission Specialist
  • 5,549 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:
MicrosoftTeams-image.png

0 Kudos
JohnCena_28
Mission Specialist
Mission Specialist
  • 3,262 Views

How to reduce layers? Are there any steps provided?

0 Kudos
SteveLibonati
Mission Specialist
Mission Specialist
  • 5,536 Views

AnandIyer
Mission Specialist
Mission Specialist
  • 5,533 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!

0 Kudos
johnpolanob
Mission Specialist
Mission Specialist
  • 5,431 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!

0 Kudos
Join the discussion
You must log in to join this conversation.