TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: How to build a minified Linux kernel for my Docker?

3 点作者 riyakhanna1983大约 5 年前
I'm trying to create a specialized (minified) Linux kernel based on my Dockerfile. Is there a solution that an automatically create a kernel image containing only the absolutely necessary functionality, specific to my Docker configuration? Default kernel shipped with a distro seems to contain a lot of unnecessary functionality, and poses high security risks.

2 条评论

shoo大约 5 年前
My understanding (perhaps wrong) is that the linux _kernel_ is in the host machine that is running the docker containers, and is not contained in the container image you define in the docker file &amp; build into an image with docker.<p>So if you don&#x27;t like how the kernel is configured, that&#x27;d require you to reconfigure the kernel on each host that will run your containers, independently of what is inside the container. But perhaps your question is about what is in the container, and not really about the kernel?<p>Maybe to make your question clearer: what are explicit examples of things that don&#x27;t you like about the current configuration that you are trying to change or disable?<p>In terms of removing unnecessary stuff from a container image, the easiest&#x2F;simplest way to do this probably depends on what application you&#x27;re packaging into a container &amp; how it is implemented.<p>For example, it is possible to build container image for a go application that starts with an empty &quot;scratch&quot; container base image (ie there&#x27;s no layer of distro such as debian, debian-slim or Alpine Linux).<p>Not sure if this is a great guide but it has an example: <a href="https:&#x2F;&#x2F;medium.com&#x2F;@chemidy&#x2F;create-the-smallest-and-secured-golang-docker-image-based-on-scratch-4752223b7324" rel="nofollow">https:&#x2F;&#x2F;medium.com&#x2F;@chemidy&#x2F;create-the-smallest-and-secured-...</a><p>The same approach of starting without a distro as the base layer of the docker container image won&#x27;t be as easy for deploying a different application that does not contain its own dependencies and assumes it can load a bunch of shared libraries that the distribution provides &amp; read files the distribution has prepared for it.
评论 #23128951 未加载
stevekemp大约 5 年前
Download the kernel source, once unpacked you can configure it to build only the modules you have currently loaded via &quot;make localmodconfig&quot;.<p>Of course if you&#x27;ve never built a kernel before you&#x27;ll need to read the documentation, and you&#x27;ll probably want to look at the Ubuntu documentation too - since you&#x27;ll want to build a .deb package, rather than a raw kernel. You&#x27;ll want to search for &quot;ubuntu make-kpkg&quot;.<p>But really you&#x27;re not going to gain much, except learning. Sure a kernel with less stuff available might save disk space, but there are easier ways to save disk-space on Ubuntu systems..
评论 #23135309 未加载