@@ -144,14 +144,14 @@ func runContainer(dockerCli command.Cli, opts *runOptions, copts *containerOptio
144144 ctx , cancelFun := context .WithCancel (context .Background ())
145145 defer cancelFun ()
146146
147- createResponse , err := createContainer (ctx , dockerCli , containerCfg , & opts .createOptions )
147+ containerID , err := createContainer (ctx , dockerCli , containerCfg , & opts .createOptions )
148148 if err != nil {
149149 reportError (stderr , "run" , err .Error (), true )
150150 return runStartContainerErr (err )
151151 }
152152 if opts .sigProxy {
153153 sigc := notifyAllSignals ()
154- go ForwardAllSignals (ctx , dockerCli , createResponse . ID , sigc )
154+ go ForwardAllSignals (ctx , dockerCli , containerID , sigc )
155155 defer signal .StopCatch (sigc )
156156 }
157157
@@ -164,26 +164,33 @@ func runContainer(dockerCli command.Cli, opts *runOptions, copts *containerOptio
164164 waitDisplayID = make (chan struct {})
165165 go func () {
166166 defer close (waitDisplayID )
167- fmt .Fprintln (stdout , createResponse . ID )
167+ _ , _ = fmt .Fprintln (stdout , containerID )
168168 }()
169169 }
170170 attach := config .AttachStdin || config .AttachStdout || config .AttachStderr
171171 if attach {
172+ detachKeys := dockerCli .ConfigFile ().DetachKeys
172173 if opts .detachKeys != "" {
173- dockerCli . ConfigFile (). DetachKeys = opts .detachKeys
174+ detachKeys = opts .detachKeys
174175 }
175176
176- closeFn , err := attachContainer (ctx , dockerCli , & errCh , config , createResponse .ID )
177+ closeFn , err := attachContainer (ctx , dockerCli , containerID , & errCh , config , types.ContainerAttachOptions {
178+ Stream : true ,
179+ Stdin : config .AttachStdin ,
180+ Stdout : config .AttachStdout ,
181+ Stderr : config .AttachStderr ,
182+ DetachKeys : detachKeys ,
183+ })
177184 if err != nil {
178185 return err
179186 }
180187 defer closeFn ()
181188 }
182189
183- statusChan := waitExitOrRemoved (ctx , dockerCli , createResponse . ID , copts .autoRemove )
190+ statusChan := waitExitOrRemoved (ctx , dockerCli , containerID , copts .autoRemove )
184191
185192 // start the container
186- if err := client .ContainerStart (ctx , createResponse . ID , types.ContainerStartOptions {}); err != nil {
193+ if err := client .ContainerStart (ctx , containerID , types.ContainerStartOptions {}); err != nil {
187194 // If we have hijackedIOStreamer, we should notify
188195 // hijackedIOStreamer we are going to exit and wait
189196 // to avoid the terminal are not restored.
@@ -201,8 +208,8 @@ func runContainer(dockerCli command.Cli, opts *runOptions, copts *containerOptio
201208 }
202209
203210 if (config .AttachStdin || config .AttachStdout || config .AttachStderr ) && config .Tty && dockerCli .Out ().IsTerminal () {
204- if err := MonitorTtySize (ctx , dockerCli , createResponse . ID , false ); err != nil {
205- fmt .Fprintln (stderr , "Error monitoring TTY size:" , err )
211+ if err := MonitorTtySize (ctx , dockerCli , containerID , false ); err != nil {
212+ _ , _ = fmt .Fprintln (stderr , "Error monitoring TTY size:" , err )
206213 }
207214 }
208215
@@ -232,15 +239,7 @@ func runContainer(dockerCli command.Cli, opts *runOptions, copts *containerOptio
232239 return nil
233240}
234241
235- func attachContainer (ctx context.Context , dockerCli command.Cli , errCh * chan error , config * container.Config , containerID string ) (func (), error ) {
236- options := types.ContainerAttachOptions {
237- Stream : true ,
238- Stdin : config .AttachStdin ,
239- Stdout : config .AttachStdout ,
240- Stderr : config .AttachStderr ,
241- DetachKeys : dockerCli .ConfigFile ().DetachKeys ,
242- }
243-
242+ func attachContainer (ctx context.Context , dockerCli command.Cli , containerID string , errCh * chan error , config * container.Config , options types.ContainerAttachOptions ) (func (), error ) {
244243 resp , errAttach := dockerCli .Client ().ContainerAttach (ctx , containerID , options )
245244 if errAttach != nil {
246245 return nil , errAttach
@@ -250,13 +249,13 @@ func attachContainer(ctx context.Context, dockerCli command.Cli, errCh *chan err
250249 out , cerr io.Writer
251250 in io.ReadCloser
252251 )
253- if config . AttachStdin {
252+ if options . Stdin {
254253 in = dockerCli .In ()
255254 }
256- if config . AttachStdout {
255+ if options . Stdout {
257256 out = dockerCli .Out ()
258257 }
259- if config . AttachStderr {
258+ if options . Stderr {
260259 if config .Tty {
261260 cerr = dockerCli .Out ()
262261 } else {
0 commit comments