From 2c5b5cfc929c8d6ffaefcbc85d2c9ad16ad301b8 Mon Sep 17 00:00:00 2001 From: Adrien Folie Date: Tue, 15 Jul 2014 19:17:20 +0200 Subject: [PATCH] Add ENV variables support to WORKDIR build command Docker-DCO-1.1-Signed-off-by: Cristian Staretu (github: unclejack) Docker-DCO-1.1-Signed-off-by: Adrien Folie (github: folieadrien) Conflicts: builder/builder.go This file has been deleted. --- docs/sources/reference/builder.md | 12 +++++++++++- integration-cli/docker_cli_build_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/docs/sources/reference/builder.md b/docs/sources/reference/builder.md index ea9122407d..23dfd6eb29 100644 --- a/docs/sources/reference/builder.md +++ b/docs/sources/reference/builder.md @@ -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] diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index 46c52c64c9..905b1cdf84 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -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]"