@@ -67,16 +67,7 @@ func main() {
67
67
log .Fatal (ssh .ListenAndServe (":2222" , nil ))
68
68
}
69
69
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 {
80
71
images , err := cli .ImageList (ctx , image.ListOptions {})
81
72
if err != nil {
82
73
log .Fatalf ("Error listing images: %v" , err )
@@ -142,7 +133,7 @@ func dockerRun(cfg *container.Config, hostcfg *container.HostConfig, sess ssh.Se
142
133
Architecture : "amd64" ,
143
134
// Variant: "minimal",
144
135
}
145
- if imageExistsLocally (cImage ) != true {
136
+ if imageExistsLocally (ctx , cImage , docker ) != true {
146
137
sess .Write ([]byte ("Fetching Image from repository .." ))
147
138
reader , pullerr := docker .ImagePull (ctx , cImage , image.PullOptions {})
148
139
if pullerr != nil {
@@ -178,7 +169,7 @@ func dockerRun(cfg *container.Config, hostcfg *container.HostConfig, sess ssh.Se
178
169
log .Fatal ("Container failed to become ready:" , err )
179
170
}
180
171
execResp , err := docker .ContainerExecCreate (ctx , resp .ID , container.ExecOptions {
181
- Cmd : []string {"/bin/bash " },
172
+ Cmd : []string {"/bin/sh " },
182
173
Tty : true ,
183
174
AttachStdin : true ,
184
175
AttachStdout : true ,
0 commit comments