mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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:
parent
89dbdb1f71
commit
8f20058307
4 changed files with 35 additions and 6 deletions
|
@ -17,7 +17,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
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
|
// Running in init mode
|
||||||
sysinit.SysInit()
|
sysinit.SysInit()
|
||||||
return
|
return
|
||||||
|
|
|
@ -51,6 +51,8 @@ type InitArgs struct {
|
||||||
Args []string
|
Args []string
|
||||||
Mtu int
|
Mtu int
|
||||||
Driver string
|
Driver string
|
||||||
|
Console string
|
||||||
|
Pipe int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Driver specific information based on
|
// Driver specific information based on
|
||||||
|
|
|
@ -28,6 +28,28 @@ var (
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
execdriver.RegisterInitFunc(DriverName, func(args *execdriver.InitArgs) error {
|
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
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -115,14 +137,15 @@ type dockerCommandFactory struct {
|
||||||
func (d *dockerCommandFactory) Create(container *libcontainer.Container,
|
func (d *dockerCommandFactory) Create(container *libcontainer.Container,
|
||||||
console, logFile string, syncFd uintptr, args []string) *exec.Cmd {
|
console, logFile string, syncFd uintptr, args []string) *exec.Cmd {
|
||||||
c := d.c
|
c := d.c
|
||||||
aname, _ := exec.LookPath("nsinit")
|
// we need to join the rootfs because nsinit will setup the rootfs and chroot
|
||||||
c.Path = aname
|
initPath := filepath.Join(c.Rootfs, c.InitPath)
|
||||||
|
|
||||||
|
c.Path = initPath
|
||||||
c.Args = append([]string{
|
c.Args = append([]string{
|
||||||
aname,
|
initPath,
|
||||||
|
"-driver", DriverName,
|
||||||
"-console", console,
|
"-console", console,
|
||||||
"-pipe", fmt.Sprint(syncFd),
|
"-pipe", fmt.Sprint(syncFd),
|
||||||
"-log", logFile,
|
|
||||||
"init",
|
|
||||||
}, args...)
|
}, args...)
|
||||||
c.SysProcAttr = &syscall.SysProcAttr{
|
c.SysProcAttr = &syscall.SysProcAttr{
|
||||||
Cloneflags: uintptr(nsinit.GetNamespaceFlags(container.Namespaces)),
|
Cloneflags: uintptr(nsinit.GetNamespaceFlags(container.Namespaces)),
|
||||||
|
|
|
@ -53,6 +53,8 @@ func SysInit() {
|
||||||
privileged = flag.Bool("privileged", false, "privileged mode")
|
privileged = flag.Bool("privileged", false, "privileged mode")
|
||||||
mtu = flag.Int("mtu", 1500, "interface mtu")
|
mtu = flag.Int("mtu", 1500, "interface mtu")
|
||||||
driver = flag.String("driver", "", "exec driver")
|
driver = flag.String("driver", "", "exec driver")
|
||||||
|
pipe = flag.Int("pipe", 0, "sync pipe fd")
|
||||||
|
console = flag.String("console", "", "console (pty slave) path")
|
||||||
)
|
)
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
@ -79,6 +81,8 @@ func SysInit() {
|
||||||
Args: flag.Args(),
|
Args: flag.Args(),
|
||||||
Mtu: *mtu,
|
Mtu: *mtu,
|
||||||
Driver: *driver,
|
Driver: *driver,
|
||||||
|
Console: *console,
|
||||||
|
Pipe: *pipe,
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := executeProgram(args); err != nil {
|
if err := executeProgram(args); err != nil {
|
||||||
|
|
Loading…
Add table
Reference in a new issue