What's the purpose of reexec.Init() in docker?

蓝咒 提交于 2021-02-08 07:19:12

问题


When reading the source code of docker1.8, I find that reexec.Init() appears in docker.go,dockerinit.go and some test files.

If reexec has registered functions, then reexec.Init() will return true so that in docker.go the process will return.

From the README.md of package reexec:

The reexec package facilitates the busybox style reexec of the docker binary that we require because of the forking limitations of using Go.

So what's the purpose of using reexec.Init()?

Is the only purpose of reexec.Init() to init the environment of a docker container?


回答1:


As you can see from commit 7321067 which introduced reexec.Init() in docker 1.2 (August 2014):

This changes the way the exec drivers work by not specifing a -driver flag on reexec.
For each of the exec drivers they register their own functions that will be matched against the argv 0 on exec and called if they match.

This also allows any functionality to be added to docker so that the binary can be reexec'd and any type of function can be called.
I moved the flag parsing on docker exec to the specific initializers so that the implementations do not bleed into one another.
This also allows for more flexability within reexec initializers to specify their own flags and options.

Init is called as the first part of the exec process and returns true if an initialization function was called

Instead of the old error message, docker silently exits if initializers are called.
Before, it was:

log.Fatal("This is a client-only binary - running it as 'dockerinit' is not supported.")


来源:https://stackoverflow.com/questions/33293483/whats-the-purpose-of-reexec-init-in-docker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!