Browse code

Add workdir support for the Buildfile

For consistency the Buildfile should have the option to
set the working directory.

Of course that is one option more to the buildfile,
so please tell me if we really want this to happen.

Marco Hennings authored on 2013/08/19 03:30:19
Showing 3 changed files
... ...
@@ -222,6 +222,11 @@ func (b *buildFile) CmdEntrypoint(args string) error {
222 222
 	return nil
223 223
 }
224 224
 
225
+func (b *buildFile) CmdWorkdir(workdir string) error {
226
+	b.config.WorkingDir = workdir
227
+	return b.commit("", b.config.Cmd, fmt.Sprintf("WORKDIR %v", workdir))
228
+}
229
+
225 230
 func (b *buildFile) CmdVolume(args string) error {
226 231
 	if args == "" {
227 232
 		return fmt.Errorf("Volume cannot be empty")
... ...
@@ -205,6 +205,14 @@ to the entrypoint.
205 205
 The ``VOLUME`` instruction will add one or more new volumes to any
206 206
 container created from the image.
207 207
 
208
+3.10 WORKDIR
209
+--------------
210
+
211
+    ``WORKDIR /path/to/workdir``
212
+
213
+The ``WORKDIR`` instruction sets the working directory in which
214
+the command given by ``CMD`` is executed.
215
+
208 216
 4. Dockerfile Examples
209 217
 ======================
210 218
 
... ...
@@ -132,6 +132,9 @@ func MergeConfig(userConf, imageConf *Config) {
132 132
 	if userConf.Entrypoint == nil || len(userConf.Entrypoint) == 0 {
133 133
 		userConf.Entrypoint = imageConf.Entrypoint
134 134
 	}
135
+	if userConf.WorkingDir == "" {
136
+		userConf.WorkingDir = imageConf.WorkingDir
137
+	}
135 138
 	if userConf.VolumesFrom == "" {
136 139
 		userConf.VolumesFrom = imageConf.VolumesFrom
137 140
 	}