mirror of https://github.com/docker/docs.git
Add chroot driver for testing
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
parent
1d8455e683
commit
8e0741f5e4
25
container.go
25
container.go
|
@ -678,18 +678,19 @@ func (container *Container) Start() (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
container.process = &execdriver.Process{
|
container.process = &execdriver.Process{
|
||||||
ID: container.ID,
|
ID: container.ID,
|
||||||
Privileged: container.hostConfig.Privileged,
|
Privileged: container.hostConfig.Privileged,
|
||||||
Rootfs: root,
|
Rootfs: root,
|
||||||
InitPath: "/.dockerinit",
|
InitPath: "/.dockerinit",
|
||||||
Entrypoint: container.Path,
|
Entrypoint: container.Path,
|
||||||
Arguments: container.Args,
|
Arguments: container.Args,
|
||||||
WorkingDir: workingDir,
|
WorkingDir: workingDir,
|
||||||
ConfigPath: container.lxcConfigPath(),
|
ConfigPath: container.lxcConfigPath(),
|
||||||
Network: en,
|
Network: en,
|
||||||
Tty: container.Config.Tty,
|
Tty: container.Config.Tty,
|
||||||
User: container.Config.User,
|
User: container.Config.User,
|
||||||
WaitLock: make(chan struct{}),
|
WaitLock: make(chan struct{}),
|
||||||
|
SysInitPath: runtime.sysInitPath,
|
||||||
}
|
}
|
||||||
container.process.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
|
container.process.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
package chroot
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/dotcloud/docker/execdriver"
|
||||||
|
"io/ioutil"
|
||||||
|
"os/exec"
|
||||||
|
"path"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type driver struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDriver() (execdriver.Driver, error) {
|
||||||
|
return &driver{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *driver) Start(c *execdriver.Process) error {
|
||||||
|
data, _ := ioutil.ReadFile(c.SysInitPath)
|
||||||
|
ioutil.WriteFile(path.Join(c.Rootfs, ".dockerinit"), data, 0644)
|
||||||
|
params := []string{
|
||||||
|
"chroot",
|
||||||
|
c.Rootfs,
|
||||||
|
"/.dockerinit",
|
||||||
|
}
|
||||||
|
// need to mount proc
|
||||||
|
params = append(params, c.Entrypoint)
|
||||||
|
params = append(params, c.Arguments...)
|
||||||
|
|
||||||
|
var (
|
||||||
|
name = params[0]
|
||||||
|
arg = params[1:]
|
||||||
|
)
|
||||||
|
aname, err := exec.LookPath(name)
|
||||||
|
if err != nil {
|
||||||
|
aname = name
|
||||||
|
}
|
||||||
|
c.Path = aname
|
||||||
|
c.Args = append([]string{name}, arg...)
|
||||||
|
|
||||||
|
if err := c.Start(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
if err := c.Wait(); err != nil {
|
||||||
|
c.WaitError = err
|
||||||
|
}
|
||||||
|
close(c.WaitLock)
|
||||||
|
}()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *driver) Kill(p *execdriver.Process, sig int) error {
|
||||||
|
return p.Process.Kill()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *driver) Wait(id string, duration time.Duration) error {
|
||||||
|
panic("No Implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *driver) Version() string {
|
||||||
|
return "0.1"
|
||||||
|
}
|
|
@ -25,19 +25,20 @@ type Network struct {
|
||||||
type Process struct {
|
type Process struct {
|
||||||
exec.Cmd
|
exec.Cmd
|
||||||
|
|
||||||
ID string
|
ID string
|
||||||
Privileged bool
|
Privileged bool
|
||||||
User string
|
User string
|
||||||
Rootfs string // root fs of the container
|
Rootfs string // root fs of the container
|
||||||
InitPath string // dockerinit
|
InitPath string // dockerinit
|
||||||
Entrypoint string
|
Entrypoint string
|
||||||
Arguments []string
|
Arguments []string
|
||||||
WorkingDir string
|
WorkingDir string
|
||||||
ConfigPath string
|
ConfigPath string
|
||||||
Tty bool
|
Tty bool
|
||||||
Network *Network // if network is nil then networking is disabled
|
Network *Network // if network is nil then networking is disabled
|
||||||
WaitLock chan struct{}
|
SysInitPath string
|
||||||
WaitError error
|
WaitLock chan struct{}
|
||||||
|
WaitError error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Process) Pid() int {
|
func (c *Process) Pid() int {
|
||||||
|
|
|
@ -88,7 +88,6 @@ func (d *driver) Start(c *execdriver.Process) error {
|
||||||
params = []string{
|
params = []string{
|
||||||
"unshare", "-m", "--", "/bin/sh", "-c", shellString,
|
"unshare", "-m", "--", "/bin/sh", "-c", shellString,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
params = append(params, "--", c.Entrypoint)
|
params = append(params, "--", c.Entrypoint)
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"github.com/dotcloud/docker/archive"
|
"github.com/dotcloud/docker/archive"
|
||||||
"github.com/dotcloud/docker/cgroups"
|
"github.com/dotcloud/docker/cgroups"
|
||||||
"github.com/dotcloud/docker/execdriver"
|
"github.com/dotcloud/docker/execdriver"
|
||||||
|
"github.com/dotcloud/docker/execdriver/chroot"
|
||||||
"github.com/dotcloud/docker/execdriver/lxc"
|
"github.com/dotcloud/docker/execdriver/lxc"
|
||||||
"github.com/dotcloud/docker/graphdriver"
|
"github.com/dotcloud/docker/graphdriver"
|
||||||
"github.com/dotcloud/docker/graphdriver/aufs"
|
"github.com/dotcloud/docker/graphdriver/aufs"
|
||||||
|
@ -735,7 +736,12 @@ func NewRuntimeFromDirectory(config *DaemonConfig) (*Runtime, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
capabilities := NewRuntimeCapabilities(false)
|
capabilities := NewRuntimeCapabilities(false)
|
||||||
ed, err := lxc.NewDriver(config.Root, capabilities.AppArmor)
|
var ed execdriver.Driver
|
||||||
|
if driver := os.Getenv("EXEC_DRIVER"); driver == "lxc" {
|
||||||
|
ed, err = lxc.NewDriver(config.Root, capabilities.AppArmor)
|
||||||
|
} else {
|
||||||
|
ed, err = chroot.NewDriver()
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,24 +182,25 @@ func getEnv(args *DockerInitArgs, key string) string {
|
||||||
func executeProgram(args *DockerInitArgs) error {
|
func executeProgram(args *DockerInitArgs) error {
|
||||||
setupEnv(args)
|
setupEnv(args)
|
||||||
|
|
||||||
if err := setupHostname(args); err != nil {
|
if false {
|
||||||
return err
|
if err := setupHostname(args); err != nil {
|
||||||
}
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if err := setupNetworking(args); err != nil {
|
if err := setupNetworking(args); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := setupCapabilities(args); err != nil {
|
if err := setupCapabilities(args); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if err := setupWorkingDirectory(args); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if err := setupWorkingDirectory(args); err != nil {
|
if err := changeUser(args); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := changeUser(args); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
path, err := exec.LookPath(args.args[0])
|
path, err := exec.LookPath(args.args[0])
|
||||||
|
|
Loading…
Reference in New Issue