Skip to content

Commit

Permalink
add interactive and tty to dockerfile, closes moby#1870
Browse files Browse the repository at this point in the history
Docker-DCO-1.1-Signed-off-by: Scott Bessler <scottbessler@gmail.com> (github: creack)
  • Loading branch information
scottbessler authored and creack committed Apr 1, 2014
1 parent f6f059d commit f4868cc
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
18 changes: 17 additions & 1 deletion docs/sources/reference/builder.rst
Expand Up @@ -418,7 +418,23 @@ instruction. For example:

The output of the final ``pwd`` command in this Dockerfile would be ``/a/b/c``.

3.11 ONBUILD
3.12 INTERACTIVE
----------------

``INTERACTIVE true``

The ``INTERACTIVE`` instruction keeps stdin open when running the
image.

3.13 TTY
--------

``TTY true``

The ``TTY`` instruction allocates a pseudo-tty when running the
image.

3.14 ONBUILD
------------

``ONBUILD [INSTRUCTION]``
Expand Down
28 changes: 28 additions & 0 deletions integration/buildfile_test.go
Expand Up @@ -437,6 +437,34 @@ func TestBuildMaintainer(t *testing.T) {
}
}

func TestBuildInteractive(t *testing.T) {
img, err := buildImage(testContextTemplate{`
from {IMAGE}
interactive true
`, nil, nil}, t, nil, true)
if err != nil {
t.Fatal(err)
}

if !img.Config.OpenStdin {
t.Fail()
}
}

func TestBuildTty(t *testing.T) {
img, err := buildImage(testContextTemplate{`
from {IMAGE}
tty true
`, nil, nil}, t, nil, true)
if err != nil {
t.Fatal(err)
}

if !img.Config.Tty {
t.Fail()
}
}

func TestBuildUser(t *testing.T) {
img, err := buildImage(testContextTemplate{`
from {IMAGE}
Expand Down
25 changes: 25 additions & 0 deletions server/buildfile.go
Expand Up @@ -21,6 +21,7 @@ import (
"reflect"
"regexp"
"sort"
"strconv"
"strings"
)

Expand Down Expand Up @@ -304,6 +305,30 @@ func (b *buildFile) CmdEntrypoint(args string) error {
return nil
}

func (b *buildFile) CmdTty(args string) error {
if arg, err := strconv.ParseBool(args); err != nil {
return err
} else {
b.config.Tty = arg
}
if err := b.commit("", b.config.Cmd, fmt.Sprintf("TTY %s", args)); err != nil {
return err
}
return nil
}

func (b *buildFile) CmdInteractive(args string) error {
if arg, err := strconv.ParseBool(args); err != nil {
return err
} else {
b.config.OpenStdin = arg
}
if err := b.commit("", b.config.Cmd, fmt.Sprintf("INTERACTIVE %s", args)); err != nil {
return err
}
return nil
}

func (b *buildFile) CmdExpose(args string) error {
portsTab := strings.Split(args, " ")

Expand Down

0 comments on commit f4868cc

Please sign in to comment.