@@ -31,12 +31,18 @@ const (
3131type Docker struct {
3232 cfg * config.Config
3333 cmd * config.Command
34+ exe string // docker
3435}
3536
3637// NewDocker creates a new Docker engine for a specific command.
3738func NewDocker (cfg * config.Config , sandbox , command string ) Engine {
3839 cmd := cfg.Commands [sandbox ][command ]
39- return & Docker {cfg , cmd }
40+ exe := "docker"
41+ // override docker with similar command
42+ if env , ok := os .LookupEnv ("DOCKER" ); ok {
43+ exe = env
44+ }
45+ return & Docker {cfg , cmd , exe }
4046}
4147
4248// Exec executes the command and returns the output.
@@ -196,10 +202,10 @@ func (e *Docker) exec(box *config.Box, step *config.Step, req Request, dir strin
196202 if step .Stdin {
197203 // pass files to container from stdin
198204 stdin := filesReader (files )
199- stdout , stderr , err = prog .RunStdin (stdin , req .ID , "docker" , args ... )
205+ stdout , stderr , err = prog .RunStdin (stdin , req .ID , e . exe , args ... )
200206 } else {
201207 // pass files to container from temp directory
202- stdout , stderr , err = prog .Run (req .ID , "docker" , args ... )
208+ stdout , stderr , err = prog .Run (req .ID , e . exe , args ... )
203209 }
204210
205211 if err == nil {
@@ -213,7 +219,7 @@ func (e *Docker) exec(box *config.Box, step *config.Step, req Request, dir strin
213219 // inside the container is not related to the "docker run" process,
214220 // and will hang forever after the "docker run" process is killed
215221 go func () {
216- err = dockerKill (req .ID )
222+ err = dockerKill (e . exe , req .ID )
217223 if err == nil {
218224 logx .Debug ("%s: docker kill ok" , req .ID )
219225 } else {
@@ -259,7 +265,7 @@ func (e *Docker) buildArgs(box *config.Box, step *config.Step, req Request, dir
259265
260266 command := expandVars (step .Command , req .ID )
261267 args = append (args , command ... )
262- logx .Debug ("%v" , args )
268+ logx .Debug ("%s %v" , e . exe , args )
263269 return args
264270}
265271
@@ -345,9 +351,9 @@ func expandVars(command []string, name string) []string {
345351}
346352
347353// dockerKill kills the container with the specified id/name.
348- func dockerKill (id string ) error {
354+ func dockerKill (exe , id string ) error {
349355 ctx , cancel := context .WithTimeout (context .Background (), killTimeout )
350356 defer cancel ()
351- cmd := exec .CommandContext (ctx , "docker" , "kill" , id )
357+ cmd := exec .CommandContext (ctx , exe , "kill" , id )
352358 return execy .Run (cmd )
353359}
0 commit comments