问题
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