如何在docker run中使用--init参数 [英] How to use --init parameter in docker run

查看:1788
本文介绍了如何在docker run中使用--init参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于 docker run,有-init -init-path 选项,但不清楚如何使用它。

There are --init and --init-path options for docker run, but it's not clear how to use it.

起初,我认为它类似于 dumb-init ,但包含在docker core中(种类为 native)。但是-init 键要求也设置-init-path ,指向'docker-init binary ,也没有提供任何线索。 Google对'docker-init'保持沉默。

At first, I thought it's something like dumb-init, but included in docker core (kind of "native"). But --init key demands --init-path to be set as well, pointing to 'docker-init binary', and gives no clue on where to take it. Google is silent about 'docker-init'.

好吧,也许我应该使用'yelp / dumb-init'或'phusion / baseimage-docker',但是这些解决方案似乎不使用 docker run -init 选项。

Okay, maybe I'm supposed to use 'yelp/dumb-init' or 'phusion/baseimage-docker', but those solutions don't seem to use docker run's --init option.

所以,我很好奇如何将这个 docker-init二进制文件设置为-init-path 呢? / p>

So, I'm curious where do I take this "docker-init binary" to set the --init-path to?

推荐答案

在run命令中指定新的docker --init选项基本上将ENTRYPOINT设置为 tini 并将CMD传递给它或您在命令行上指定的任何内容。

Specifiying the new docker --init option in the run command basically sets ENTRYPOINT to tini and passes the CMD to it or whatever you specify on the commandline.

如果没有init,则CMD变为pid1。在这种情况下,/ bin / bash

For example, without init, CMD becomes pid 1. In this case, /bin/bash

docker run -ti --rm ubuntu:16.04 /bin/bash
root@d740f7360840:/# ps -fA
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  1 03:30 ?        00:00:00 /bin/bash
root        11     1  0 03:30 ?        00:00:00 ps -fA

通过--init,tini(/ dev / init)变为pid 1

With --init, tini (/dev/init) becomes pid 1

docker run -ti --init --rm ubuntu:16.04 /bin/bash
root@5b5fe6ee71b5:/# ps -fA
UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  1 03:30 ?        00:00:00 /dev/init -- /bin/bash
root         7     1  0 03:30 ?        00:00:00 /bin/bash
root        12     7  0 03:30 ?        00:00:00 ps -fA

tini是一流的初始化进程,可以作为pid运行1正确。 pid 1进程必须正确地获取分叉的子进程,否则将发生坏事,例如资源泄漏和出现僵尸。

tini is a first class init process that can be run as pid 1 correctly. A pid 1 process must reap forked child processes correctly, if it doesn't then bad things happen like resources get leaked and zombies appear.

这是应用程序所需要的该分叉并且在编写时并没有考虑到孩子的收获,因为通常他们会将其留给init系统处理。一个经典的例子是Java Jenkins应用程序。

This is what you want for applications that fork and haven't been written with child reaping in mind as normally they would leave this up to the init system. A classic example is java Jenkins applications.

这篇关于如何在docker run中使用--init参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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