Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem that the volume of Docker image is too large

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "how to solve the problem of Docker image volume is too large", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to solve the problem of Docker image volume is too large" this article.

Problems with virtual machines

At first, everyone used the virtual machine as the running environment of the software to provide services. In order to run your Service on a virtual machine, you have to run a lot of programs:

System process

Scheduled task

SSH

Install Agent

Install Bash

Install a lot of libs

In fact, you just want your Service to run, but you have to maintain a 40GB virtual machine.

And then you start trying Docker.

When you start trying Docker, you don't hesitate to choose the same image as the previous virtual machine: Ubuntu 1404, copy the contents of the previous virtual machine to the Docker image, install a bunch of software, and finally find that your Docker image has 8GB.

Google's Docker Image Construction practice

Find the smallest basic image

Alpine Linux is an operating system based on musl and BusyBox, which aims to provide users with more efficient use of resources. Its characteristic is that it is small in size, and the smallest Alpine Linux volume can be only 5MB. Some Google teams use Alpine Linux as the basic mirror image of Docker Build.

Purpose: just to run Service

Google believes that in order to run a Service, there is no need to package those unrelated packages and programs into a container, in other words, the Docker image leaves only what you need, and everything else is deleted to get the smallest image. The following points need to be considered:

1. The compiled binary file (obtained from Artifactory)

2. All dependencies of the program (obtained from Artifactory)

3. The runtime of the program language (libc,JRE,node, … )

4. Middleware between any program and Kernel

In fact, all this information is already known to the build tools.

Google's build tool Bazel

Before introducing Bazel, let's introduce Google's development model. For server-side code base, Google's development process is as follows:

1. All the server-side code bases are in a huge version control system

2. Everyone uses Bazel to build software

3. Different groups are responsible for different parts of the source tree, and all components are used as BUILD targets.

4. The branch is mainly used to manage releases, so everyone develops software on the latest version

Bazel (https://bazel.build/) is a tool used internally by Google to build its own server-side software. It is now an open source project contributed by Google to help developers build and test software faster and more reliably.

As you can see from the figure above, Bazel has the concept of WORDSPACE, and the WORDSPACE file is used to prepare all the materials and sources on which the Docker image is built. The BUILD file is used to tell Bazel what commands the image should use to build, how to build, and how to test.

Using Bazel's declarative languages: WORKSPACE and BUILD, developers can use files to describe the entire build and deployment environment. Google has been using Bazel to build Docker for many years, and it brings the following benefits to Google:

1. Support cross-platform building, distributed caching, optimized dependency parsing, parallel building, and incremental building.

2. Support multiple languages (Java, Cellular, Android, iOS, Go, etc.).

3. Cross-platform.

4. Horizontal extension and custom extension.

Bazel is the cornerstone of the idea that since Bazel requires all dependencies to be fully specified, we can predict which programs and tests are affected by the changes and execute them before committing.

Distroless image build file provided by Google

Distroless (https://github.com/GoogleCloudPlatform/distroless) is an image build file used internally by Google, including Java, Node, Python and other image build files. Distroless only contains the minimum image needed to run the service, and does not include package management tools, shell command line and other features.

Why do you need these mirrors? These images are the product of the best practices of Google and other large companies, and after vulnerability scanning, the images are constantly updated to maintain security.

How to use it? The BUILD file of the build image provided by Distroless, which can be built directly through Bazel.

Google introduced how to solve the problem of too large images internally, as well as Bazel, a build tool used for large-scale concurrent builds and testing, and opened up the Docker image build file Distroless project. If you think your mirror image is too large, you can refer to Google's practice and experience their tools.

The above is all the contents of the article "how to solve the problem of too large Docker image size". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report