Now that we have analyzed the general process of ‘runc create’ and know that the ‘runc create’ will execute ‘runc init’ parent process, the parent process will clone child process, and the child process will clone a grandchild process, and this grandchild process will execute the user defined process.
Once I decide to draw a pic of these four process’ relation. But I found a detail pic here. I just reference it here.
So let’s see these process’ work.
This is runc:[0:PARENT].
Got the config from runc create process. This is done by
nl_parse(pipenum, &config); //corresponding runc create code :io.Copy(p.messageSockPair.parent, p.bootstrapData)
This is runc:[1:CHILD].
This is runc:[2:INIT].
The first clone is to let the parent to set the uid/gid mapping. The second clone is to make the pid namespace take effect. After these double clone, the child process is totally in the desirable new environment.