Skip to content

Commit faa52f3

Browse files
committed
fallback to sh if bash not available
1 parent e4d337d commit faa52f3

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

main.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func dockerRun(cfg *container.Config, hostcfg *container.HostConfig, sess ssh.Se
168168
}
169169
startErr := docker.ContainerStart(ctx, resp.ID, container.StartOptions{})
170170
if startErr != nil {
171-
ErrorPrint("Unable to start container: %v", err)
171+
ErrorPrint("Unable to start container: %s", startErr)
172172
sess.Write([]byte("Unable to pull requested image" + string(startErr.Error()) + "\n"))
173173
return
174174
}
@@ -180,22 +180,26 @@ func dockerRun(cfg *container.Config, hostcfg *container.HostConfig, sess ssh.Se
180180
return
181181
}
182182
execResp, err := docker.ContainerExecCreate(ctx, resp.ID, container.ExecOptions{
183-
Cmd: []string{"/bin/sh"},
183+
Cmd: []string{"/bin/sh", "-c", "/bin/bash || /bin/sh"},
184184
Tty: true,
185185
AttachStdin: true,
186186
AttachStdout: true,
187187
AttachStderr: true,
188188
})
189189
if err != nil {
190+
ErrorPrint("Error creating container exec: [%s]", err.Error())
190191
return
191192
}
192193
InfoPrint("Attaching container: %s", resp.ID)
193194
stream, err := docker.ContainerExecAttach(ctx, execResp.ID, container.ExecStartOptions{
194195
Tty: true,
195196
})
197+
if err != nil {
198+
ErrorPrint("Error during container attach: [%v]", err.Error())
199+
return
200+
}
196201

197202
outputErr := make(chan error)
198-
199203
go func() {
200204
var err error
201205
if cfg.Tty {

0 commit comments

Comments
 (0)