Move tty into container.json

Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
Michael Crosby 2014-02-21 13:53:11 -08:00
parent cdd46116e7
commit b3d4ac7fc0
5 changed files with 11 additions and 12 deletions

View File

@ -17,6 +17,7 @@ Sample `container.json` file:
```json
{
"hostname": "koye",
"tty": true,
"environment": [
"HOME=/",
"PATH=PATH=$PATH:/bin:/usr/bin:/sbin:/usr/sbin",
@ -55,7 +56,7 @@ Sample `container.json` file:
"cgroups": {
"name": "docker-koye",
"parent": "docker",
"memory": 524800
"memory": 5248000
}
}
```
@ -72,11 +73,9 @@ rootfs and copy a `container.json` file into the directory with your specified c
To execution `/bin/bash` in the current directory as a container just run:
```bash
nsinit -tty exec /bin/bash
nsinit exec /bin/bash
```
If you want a proper tty setup inside the new container you must use the `-tty` flag when running nsinit.
If you wish to spawn another process inside the container while your current bash session is
running just run the exact same command again to get another bash shell or change the command. If the original process dies, PID 1, all other processes spawned inside the container will also be killed and the namespace will be removed.

View File

@ -12,6 +12,7 @@ type Container struct {
User string `json:"user,omitempty"` // user to execute the process as
WorkingDir string `json:"working_dir,omitempty"` // current working directory
Env []string `json:"environment,omitempty"` // environment to set
Tty bool `json:"tty,omitempty"` // setup a proper tty or not
Namespaces Namespaces `json:"namespaces,omitempty"` // namespaces to apply
Capabilities Capabilities `json:"capabilities,omitempty"` // capabilities to drop
Network *Network `json:"network,omitempty"` // nil for host's network stack

View File

@ -1,5 +1,6 @@
{
"hostname": "koye",
"tty": true,
"environment": [
"HOME=/",
"PATH=PATH=$PATH:/bin:/usr/bin:/sbin:/usr/sbin",
@ -38,6 +39,6 @@
"cgroups": {
"name": "docker-koye",
"parent": "docker",
"memory": 524800
"memory": 5248000
}
}

View File

@ -18,7 +18,7 @@ import (
// Exec performes setup outside of a namespace so that a container can be
// executed. Exec is a high level function for working with container namespaces.
func Exec(container *libcontainer.Container, tty bool, args []string) (int, error) {
func Exec(container *libcontainer.Container, args []string) (int, error) {
var (
master *os.File
console string
@ -28,7 +28,7 @@ func Exec(container *libcontainer.Container, tty bool, args []string) (int, erro
outPipe, errPipe io.ReadCloser
)
if tty {
if container.Tty {
master, console, err = createMasterAndConsole()
if err != nil {
return -1, err
@ -44,7 +44,7 @@ func Exec(container *libcontainer.Container, tty bool, args []string) (int, erro
system.UsetCloseOnExec(r.Fd())
command := createCommand(container, console, r.Fd(), args)
if !tty {
if !container.Tty {
if inPipe, err = command.StdinPipe(); err != nil {
return -1, err
}
@ -86,7 +86,7 @@ func Exec(container *libcontainer.Container, tty bool, args []string) (int, erro
w.Close()
r.Close()
if tty {
if container.Tty {
go io.Copy(os.Stdout, master)
go io.Copy(master, os.Stdin)

View File

@ -14,7 +14,6 @@ import (
var (
console string
tty bool
pipeFd int
)
@ -25,7 +24,6 @@ var (
func init() {
flag.StringVar(&console, "console", "", "console (pty slave) path")
flag.BoolVar(&tty, "tty", false, "create a tty")
flag.IntVar(&pipeFd, "pipe", 0, "sync pipe fd")
flag.Parse()
@ -52,7 +50,7 @@ func main() {
if nspid > 0 {
exitCode, err = nsinit.ExecIn(container, nspid, flag.Args()[1:])
} else {
exitCode, err = nsinit.Exec(container, tty, flag.Args()[1:])
exitCode, err = nsinit.Exec(container, flag.Args()[1:])
}
if err != nil {
log.Fatal(err)