In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to build a smaller container image of linux, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!
Microdnf
Fedora's DNF is written in Python because it has a variety of plug-ins, so its design is extensible. But there is an alternative to the Fedora basic container image, which uses a smaller package manager called microdnf, written in C. To use this smallest mirror in Dockerfile, the FROM line should look like this:
FROM registry.fedoraproject.org/fedora-minimal:30
If your image does not require a typical DNF dependency like Python, for example, if you are making a NodeJS image, this is an important saving item.
Install and clean up in one tier
To save space, it is important to delete warehouse metadata using dnf clean all or its microdnf equivalent microdnf clean all. However, you should not do this in two steps, as this will actually save the files in the container image and then mark them for deletion in another layer. To do this correctly, you should complete the installation and cleanup in this step:
FROM registry.fedoraproject.org/fedora-minimal:30RUN microdnf install nodejs & & microdnf clean all uses microdnf for modularization
Modularity is a way to choose different stack versions for you. For example, you may need to use a non-LTS NodeJS v11 in a project, an old LTS NodeJS v8 for another, and a * LTS NodeJS v10 for another. You can use colons to specify the stream.
# dnf module list# dnf module install nodejs:8
The dnf module install command means two commands, one to enable streaming and the other to install nodejs from it.
# dnf module enable nodejs:8# dnf install nodejs
Although microdnf does not provide any commands related to modularity, modules with configuration files can be enabled, and libdnf (used by microdnf) seems to support modular flows. The file looks like this:
/ etc/dnf/modules.d/ nodejs.module[nodejs] name=nodejsstream=8profiles=state=enabled
The complete Dockerfile using modular microdnf is as follows:
FROM registry.fedoraproject.org/fedora-minimal:30RUN\ echo-e "[nodejs]\ nname=nodejs\ nstream=8\ nprofiles=\ nstate=enabled\ n" > / etc/dnf/modules.d/nodejs.module & &\ microdnf install nodejs zopfli findutils busybox & &\ microdnf clean all Multi-stage Construction
In many cases, you may need a large number of build-time dependencies that do not need to be used to run the software, such as building a Go binary that statically links dependencies. Multi-stage build is an effective way to separate application build from application runtime.
For example, the following Dockerfile builds a Go application confd.
# building containerFROM registry.fedoraproject.org/fedora-minimal AS buildRUN mkdir / go & & microdnf install golang & & microdnf clean allWORKDIR / goRUN export GOPATH=/go; CGO_ENABLED=0 go get github.com/kelseyhightower/confd FROM registry.fedoraproject.org/fedora-minimalWORKDIR / COPY-- from=build / go/bin/confd / usr/local/binCMD ["confd"]
Complete the multi-phase build by adding AS after the FROM directive and adding another FROM from the base container image, and then using the COPY-- from= directive to copy the content from the built container to the second container.
You can build and run this Dockerfile using podman:
$podman build-t myconfd. $podman run-it myconfd is all the content of the article "how to build smaller container images for linux". 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.