Browse code

introduce `workingdir` option for docker exec

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>

Nicolas De Loof authored on 2017/12/01 17:06:07
Showing 4 changed files
... ...
@@ -7269,6 +7269,9 @@ paths:
7269 7269
               User:
7270 7270
                 type: "string"
7271 7271
                 description: "The user, and optionally, group to run the exec process inside the container. Format is one of: `user`, `user:group`, `uid`, or `uid:gid`."
7272
+              WorkingDir:
7273
+                type: "string"
7274
+                description: "The working directory for the exec process inside the container."
7272 7275
             example:
7273 7276
               AttachStdin: false
7274 7277
               AttachStdout: true
... ...
@@ -50,6 +50,7 @@ type ExecConfig struct {
50 50
 	Detach       bool     // Execute in detach mode
51 51
 	DetachKeys   string   // Escape keys for detach
52 52
 	Env          []string // Environment variables
53
+	WorkingDir   string   // Working directory
53 54
 	Cmd          []string // Execution commands and args
54 55
 }
55 56
 
... ...
@@ -122,6 +122,7 @@ func (d *Daemon) ContainerExecCreate(name string, config *types.ExecConfig) (str
122 122
 	execConfig.Tty = config.Tty
123 123
 	execConfig.Privileged = config.Privileged
124 124
 	execConfig.User = config.User
125
+	execConfig.WorkingDir = config.WorkingDir
125 126
 
126 127
 	linkedEnv, err := d.setupLinkedContainers(cntr)
127 128
 	if err != nil {
... ...
@@ -131,6 +132,9 @@ func (d *Daemon) ContainerExecCreate(name string, config *types.ExecConfig) (str
131 131
 	if len(execConfig.User) == 0 {
132 132
 		execConfig.User = cntr.Config.User
133 133
 	}
134
+	if len(execConfig.WorkingDir) == 0 {
135
+		execConfig.WorkingDir = cntr.Config.WorkingDir
136
+	}
134 137
 
135 138
 	d.registerExecCommand(cntr, execConfig)
136 139
 
... ...
@@ -211,7 +215,7 @@ func (d *Daemon) ContainerExecStart(ctx context.Context, name string, stdin io.R
211 211
 		Args:     append([]string{ec.Entrypoint}, ec.Args...),
212 212
 		Env:      ec.Env,
213 213
 		Terminal: ec.Tty,
214
-		Cwd:      c.Config.WorkingDir,
214
+		Cwd:      ec.WorkingDir,
215 215
 	}
216 216
 	if p.Cwd == "" {
217 217
 		p.Cwd = "/"
... ...
@@ -31,6 +31,7 @@ type Config struct {
31 31
 	Tty          bool
32 32
 	Privileged   bool
33 33
 	User         string
34
+	WorkingDir   string
34 35
 	Env          []string
35 36
 	Pid          int
36 37
 }