我应该在Docker中构建OS吗? [英] Should i build OS in docker?

查看:103
本文介绍了我应该在Docker中构建OS吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为php + apache上的简单项目创建环境,而我是docker的新手。
我没有得到构建alpine + LAMP
之类的东西,或者只是构建LAMP,所有运行Ubuntu的机器之间的区别。我需要操作系统吗?

I'm creating environment for simple projects on php + apache and i'm new to docker. I don't get the difference between building something like alpine+LAMP or just build a LAMP, all machines running Ubuntu. Do i need an OS?

推荐答案

是。您需要一个操作系统(实际上,它不是完整的操作系统,我将在后面解释)。为什么?好的,让我解释一下。

Yes. You need a OS(actually, it's not complete OS. i will explain later). Why? Ok, let me explain.


  1. 使用Docker运行应用程序时,您正在容器中运行此应用程序。

  2. 此容器不使用您的OS文件系统和库。相反,它使用 syscall 直接与内核通信。

  1. When you are running your application using Docker, you are running this application inside a container.
  2. This container does not use your OS file system and libraries. Instead, it directly communicate with kernel using syscall.

现在的问题是,您的应用程序将在其中获得运行所需的文件系统和库?

Now the question is, where you application will get the necessary file system and libraries to run?

在这里,基本操作系统(即高山映像)开始发挥作用。此基本映像不是完整的linux OS。它没有内核。它提供了一个文件系统和一些必要的库来运行您的应用程序。

Here, the base OS(i.e. alpine image) come into play. This base image is not complete linux OS. It does not have a kernel. It provides a file system and some necessary libraries to run your application.

UPD:但是,您可以构建不需要任何基本OS映像的docker映像(从< a href = https://docs.docker.com/develop/develop-images/baseimages/#create-a-simple-parent-image-using-scratch rel = nofollow noreferrer>从头开始) 。但是它要求您的应用程序必须静态编译,这意味着它在二进制文件中包含运行该应用程序所需的所有必需库。

UPD: However, you can build a docker image that do not require any base OS image(from scratch). But it require that your application must be statically compiled which means it includes all necessary library within the binary that are required to run the application.

这篇关于我应该在Docker中构建OS吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆