如何在Dockerfile中安装需要重启的内容? [英] How do you install something that needs restart in a Dockerfile?

查看:382
本文介绍了如何在Dockerfile中安装需要重启的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我的安装说明如下:

Suppose I have installation instructions as follows:


  1. 执行某些操作。

  2. 重新启动计算机。

  3. 做其他事情。

我如何在Dockerfile中表达这一点?

How do I express that in a Dockerfile?

推荐答案

这完全取决于他们为什么需要重新启动。对于Linux,重新启动计算机通常会指示内核已修改,尽管这可能是更简单的操作,例如更改用户权限(可以通过注销然后重新登录来处理)。如果安装尝试将操作系统级别更改为内核,则如果在容器内部完成安装应该会失败。默认情况下,容器会隔离应用程序并将其限制在运行中的主机操作系统上,这会影响主机或其他正在运行的容器。

This entirely depends on why they require a reboot. For Linux, rebooting a machine would typically indicate a kernel modification, though it's possible it's for something more simple like a change in user permissions (which would be handled by logging out and back in again). If the install is trying to make an OS level change to the kernel, it should fail if done inside of a container. By default, containers isolate and restrict what the application can do to the running host OS which would impact the host or other running containers.

如果,重新启动将强制执行要重新启动应用程序服务,您应该意识到这种设计不能很好地映射到容器,因为每个RUN命令仅在隔离的环境中运行该命令。通过仅运行该命令,这还表明通常不会在操作系统启动时启动的任何OS服务(cron,sendmail或您的应用程序)都不会在容器中启动。因此,除了重新启动任何依赖服务之外,您还需要找到一种运行安装命令的方法。

If, the reboot is to force the application service to restart, you should realize that this design doesn't map well to a container since each RUN command runs just that command in an isolated environment. And by running only that command, this also indicates that any OS services that would normally be started on OS bootup (cron, sendmail, or your application) will not be started in the container. Therefore, you'll need to find a way to run the installation command in addition to restarting any dependent services.

我可以想到的最后一种情况是他们想要不同的用户权限使登录用户生效。在这种情况下,下一个RUN命令将以先前RUN命令的任何更改的访问权限运行请求的命令。因此,您无需采取任何特定的操作来进行重新启动,只需执行安装步骤,就好像每个步骤之间都可以完全重新启动一样。

The last scenario I can think of they want different user permissions to take effect to the logged in user. In that case, the next RUN command will run the requested command with any changed access from prior RUN commands. So there's no need to take any specific action of your own to do a reboot, simply perform the install steps as if there's a complete restart between each step.

这篇关于如何在Dockerfile中安装需要重启的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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