1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Add ENV variables support to WORKDIR build command

Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
Docker-DCO-1.1-Signed-off-by: Adrien Folie <folie.adrien@gmail.com> (github: folieadrien)

Conflicts:
	builder/builder.go
		This file has been deleted.
This commit is contained in:
Adrien Folie 2014-07-15 19:17:20 +02:00 committed by unclejack
parent 3f2e4e94d7
commit 2c5b5cfc92
2 changed files with 35 additions and 1 deletions

View file

@ -531,9 +531,19 @@ instruction. For example:
WORKDIR c
RUN pwd
The output of the final `pwd` command in this Dockerfile would be
The output of the final `pwd` command in this `Dockerfile` would be
`/a/b/c`.
The `WORKDIR` instruction can resolve environment variables previously set using
`ENV`. You can only use environment variables explicitly set in the `Dockerfile`.
For example:
ENV DIRPATH /path
WORKDIR $DIRPATH/$DIRNAME
The output of the final `pwd` command in this `Dockerfile` would be
`/path/$DIRNAME`
## ONBUILD
ONBUILD [INSTRUCTION]

View file

@ -973,6 +973,30 @@ func TestBuildRelativeWorkdir(t *testing.T) {
logDone("build - relative workdir")
}
func TestBuildWorkdirWithEnvVariables(t *testing.T) {
name := "testbuildworkdirwithenvvariables"
expected := "/test1/test2/$MISSING_VAR"
defer deleteImages(name)
_, err := buildImage(name,
`FROM busybox
ENV DIRPATH /test1
ENV SUBDIRNAME test2
WORKDIR $DIRPATH
WORKDIR $SUBDIRNAME/$MISSING_VAR`,
true)
if err != nil {
t.Fatal(err)
}
res, err := inspectField(name, "Config.WorkingDir")
if err != nil {
t.Fatal(err)
}
if res != expected {
t.Fatalf("Workdir %s, expected %s", res, expected)
}
logDone("build - workdir with env variables")
}
func TestBuildEnv(t *testing.T) {
name := "testbuildenv"
expected := "[PATH=/test:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin PORT=2375]"