Skip to content

Commit d779a81

Browse files
committed
pass context, start sh instead of bash
1 parent 7560b55 commit d779a81

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

main.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,7 @@ func main() {
6767
log.Fatal(ssh.ListenAndServe(":2222", nil))
6868
}
6969

70-
func imageExistsLocally(imageName string) bool {
71-
ctx := context.Background()
72-
73-
// Create a Docker client
74-
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
75-
if err != nil {
76-
log.Fatalf("Error creating Docker client: %v", err)
77-
}
78-
79-
// List images with filters
70+
func imageExistsLocally(ctx context.Context, imageName string, cli *client.Client) bool {
8071
images, err := cli.ImageList(ctx, image.ListOptions{})
8172
if err != nil {
8273
log.Fatalf("Error listing images: %v", err)
@@ -142,7 +133,7 @@ func dockerRun(cfg *container.Config, hostcfg *container.HostConfig, sess ssh.Se
142133
Architecture: "amd64",
143134
// Variant: "minimal",
144135
}
145-
if imageExistsLocally(cImage) != true {
136+
if imageExistsLocally(ctx, cImage, docker) != true {
146137
sess.Write([]byte("Fetching Image from repository .."))
147138
reader, pullerr := docker.ImagePull(ctx, cImage, image.PullOptions{})
148139
if pullerr != nil {
@@ -178,7 +169,7 @@ func dockerRun(cfg *container.Config, hostcfg *container.HostConfig, sess ssh.Se
178169
log.Fatal("Container failed to become ready:", err)
179170
}
180171
execResp, err := docker.ContainerExecCreate(ctx, resp.ID, container.ExecOptions{
181-
Cmd: []string{"/bin/bash"},
172+
Cmd: []string{"/bin/sh"},
182173
Tty: true,
183174
AttachStdin: true,
184175
AttachStdout: true,

0 commit comments

Comments
 (0)