Skip to content

Commit

Permalink
Import nsenter in docker.
Browse files Browse the repository at this point in the history
Docker-DCO-1.1-Signed-off-by: Vishnu Kannan <[email protected]> (github: vishh)
  • Loading branch information
vishh committed Sep 15, 2014
1 parent 985d579 commit e1cf95b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
5 changes: 2 additions & 3 deletions daemon/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (

type ExecConfig struct {
ProcessConfig execdriver.ProcessConfig
StreamConfig StreamConfig
OpenStdin bool
StreamConfig
OpenStdin bool
}

func (d *Daemon) ContainerExec(job *engine.Job) engine.Status {
Expand Down Expand Up @@ -92,7 +92,6 @@ func (d *Daemon) ContainerExec(job *engine.Job) engine.Status {
attachErr = d.Attach(&execConfig.StreamConfig, config.AttachStdin, false, config.Tty, cStdin, cStdinCloser, cStdout, cStderr)
}()

log.Debugf("Exec Config is %+v\n", execConfig)
go func() {
err := container.Exec(execConfig)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions daemon/execdriver/native/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/docker/libcontainer/cgroups/systemd"
consolepkg "github.com/docker/libcontainer/console"
"github.com/docker/libcontainer/namespaces"
_ "github.com/docker/libcontainer/namespaces/nsenter"
"github.com/docker/libcontainer/system"
)

Expand Down
1 change: 1 addition & 0 deletions daemon/execdriver/native/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func nsenterExec() {
}
}

// TODO(vishh): Add support for running in priviledged mode and running as a different user.
func (d *driver) Exec(c *execdriver.Command, processConfig *execdriver.ProcessConfig, pipes *execdriver.Pipes, startCallback execdriver.StartCallback) (int, error) {
active := d.activeContainers[c.ID]
if active == nil {
Expand Down
21 changes: 9 additions & 12 deletions runconfig/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ type ExecConfig struct {
AttachStdout bool
Detach bool
Cmd []string
Hostname string
}

func ExecConfigFromJob(job *engine.Job) *ExecConfig {
Expand All @@ -37,14 +36,11 @@ func ExecConfigFromJob(job *engine.Job) *ExecConfig {

func ParseExec(cmd *flag.FlagSet, args []string) (*ExecConfig, error) {
var (
flPrivileged = cmd.Bool([]string{"#privileged", "-privileged"}, false, "Give extended privileges to this container")
flStdin = cmd.Bool([]string{"i", "-interactive"}, false, "Keep STDIN open even if not attached")
flTty = cmd.Bool([]string{"t", "-tty"}, false, "Allocate a pseudo-TTY")
flHostname = cmd.String([]string{"h", "-hostname"}, "", "Container host name")
flUser = cmd.String([]string{"u", "-user"}, "", "Username or UID")
flDetach = cmd.Bool([]string{"d", "-detach"}, false, "Detached mode: run command in the background")
execCmd []string
container string
flStdin = cmd.Bool([]string{"i", "-interactive"}, false, "Keep STDIN open even if not attached")
flTty = cmd.Bool([]string{"t", "-tty"}, false, "Allocate a pseudo-TTY")
flDetach = cmd.Bool([]string{"d", "-detach"}, false, "Detached mode: run command in the background")
execCmd []string
container string
)
if err := cmd.Parse(args); err != nil {
return nil, err
Expand All @@ -56,12 +52,13 @@ func ParseExec(cmd *flag.FlagSet, args []string) (*ExecConfig, error) {
}

execConfig := &ExecConfig{
User: *flUser,
Privileged: *flPrivileged,
// TODO(vishh): Expose '-u' flag once it is supported.
User: "",
// TODO(vishh): Expose '-p' flag once it is supported.
Privileged: false,
Tty: *flTty,
Cmd: execCmd,
Container: container,
Hostname: *flHostname,
Detach: *flDetach,
}

Expand Down

0 comments on commit e1cf95b

Please sign in to comment.