@@ -18,6 +18,7 @@ import (
1818
1919 "github.com/Sirupsen/logrus"
2020 "github.com/docker/docker/api"
21+ "github.com/docker/docker/api/types"
2122 "github.com/docker/docker/api/types/container"
2223 "github.com/docker/docker/api/types/strslice"
2324 "github.com/docker/docker/builder"
@@ -279,12 +280,26 @@ func workdir(b *Builder, args []string, attributes map[string]bool, original str
279280 return err
280281 }
281282
282- // NOTE: You won't find the "mkdir" for the directory in here. Rather we
283- // just set the value in the image's runConfig.WorkingDir property
284- // and container.SetupWorkingDirectory() will create it automatically
285- // for us the next time the image is used to create a container.
283+ // For performance reasons, we explicitly do a create/mkdir now
284+ // This avoids having an unnecessary expensive mount/unmount calls
285+ // (on Windows in particular) during each container create.
286+ // Prior to 1.13, the mkdir was deferred and not executed at this step.
287+ if b .disableCommit {
288+ // Don't call back into the daemon if we're going through docker commit --change "WORKDIR /foo".
289+ // We've already updated the runConfig and that's enough.
290+ return nil
291+ }
292+ b .runConfig .Image = b .image
293+ container , err := b .docker .ContainerCreate (types.ContainerCreateConfig {Config : b .runConfig }, true )
294+ if err != nil {
295+ return err
296+ }
297+ b .tmpContainers [container .ID ] = struct {}{}
298+ if err := b .docker .ContainerCreateWorkdir (container .ID ); err != nil {
299+ return err
300+ }
286301
287- return b .commit ("" , b .runConfig .Cmd , fmt . Sprintf ( "WORKDIR %v" , b .runConfig .WorkingDir ) )
302+ return b .commit (container . ID , b .runConfig .Cmd , "WORKDIR " + b .runConfig .WorkingDir )
288303}
289304
290305// RUN some command yo
0 commit comments