Compile nsinit into docker for use with dockerinit

Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
Michael Crosby 2014-02-24 12:21:13 -08:00
parent 89dbdb1f71
commit 8f20058307
4 changed files with 35 additions and 6 deletions

View File

@ -17,7 +17,7 @@ import (
)
func main() {
if selfPath := utils.SelfPath(); selfPath == "/sbin/init" || selfPath == "/.dockerinit" {
if selfPath := utils.SelfPath(); selfPath == "/sbin/init" || strings.Contains(selfPath, "/.dockerinit") {
// Running in init mode
sysinit.SysInit()
return

View File

@ -51,6 +51,8 @@ type InitArgs struct {
Args []string
Mtu int
Driver string
Console string
Pipe int
}
// Driver specific information based on

View File

@ -28,6 +28,28 @@ var (
func init() {
execdriver.RegisterInitFunc(DriverName, func(args *execdriver.InitArgs) error {
var container *libcontainer.Container
f, err := os.Open("container.json")
if err != nil {
return err
}
if err := json.NewDecoder(f).Decode(&container); err != nil {
f.Close()
return err
}
f.Close()
cwd, err := os.Getwd()
if err != nil {
return err
}
syncPipe, err := nsinit.NewSyncPipeFromFd(0, uintptr(args.Pipe))
if err != nil {
return err
}
if err := nsinit.Init(container, cwd, args.Console, syncPipe, args.Args); err != nil {
return err
}
return nil
})
}
@ -115,14 +137,15 @@ type dockerCommandFactory struct {
func (d *dockerCommandFactory) Create(container *libcontainer.Container,
console, logFile string, syncFd uintptr, args []string) *exec.Cmd {
c := d.c
aname, _ := exec.LookPath("nsinit")
c.Path = aname
// we need to join the rootfs because nsinit will setup the rootfs and chroot
initPath := filepath.Join(c.Rootfs, c.InitPath)
c.Path = initPath
c.Args = append([]string{
aname,
initPath,
"-driver", DriverName,
"-console", console,
"-pipe", fmt.Sprint(syncFd),
"-log", logFile,
"init",
}, args...)
c.SysProcAttr = &syscall.SysProcAttr{
Cloneflags: uintptr(nsinit.GetNamespaceFlags(container.Namespaces)),

View File

@ -53,6 +53,8 @@ func SysInit() {
privileged = flag.Bool("privileged", false, "privileged mode")
mtu = flag.Int("mtu", 1500, "interface mtu")
driver = flag.String("driver", "", "exec driver")
pipe = flag.Int("pipe", 0, "sync pipe fd")
console = flag.String("console", "", "console (pty slave) path")
)
flag.Parse()
@ -79,6 +81,8 @@ func SysInit() {
Args: flag.Args(),
Mtu: *mtu,
Driver: *driver,
Console: *console,
Pipe: *pipe,
}
if err := executeProgram(args); err != nil {