@@ -46,7 +46,7 @@ func NewContainerService(db *database.DB, eventService *EventService, dockerServ
4646}
4747
4848func (s * ContainerService ) StartContainer (ctx context.Context , containerID string , user models.User ) error {
49- dockerClient , err := s .dockerService .GetClient ()
49+ dockerClient , err := s .dockerService .GetClient (ctx )
5050 if err != nil {
5151 s .eventService .LogErrorEvent (ctx , models .EventTypeContainerError , "container" , containerID , "" , user .ID , user .Username , "0" , err , models.JSON {"action" : "start" })
5252 return fmt .Errorf ("failed to connect to Docker: %w" , err )
@@ -70,7 +70,7 @@ func (s *ContainerService) StartContainer(ctx context.Context, containerID strin
7070}
7171
7272func (s * ContainerService ) StopContainer (ctx context.Context , containerID string , user models.User ) error {
73- dockerClient , err := s .dockerService .GetClient ()
73+ dockerClient , err := s .dockerService .GetClient (ctx )
7474 if err != nil {
7575 s .eventService .LogErrorEvent (ctx , models .EventTypeContainerError , "container" , containerID , "" , user .ID , user .Username , "0" , err , models.JSON {"action" : "stop" })
7676 return fmt .Errorf ("failed to connect to Docker: %w" , err )
@@ -95,7 +95,7 @@ func (s *ContainerService) StopContainer(ctx context.Context, containerID string
9595}
9696
9797func (s * ContainerService ) RestartContainer (ctx context.Context , containerID string , user models.User ) error {
98- dockerClient , err := s .dockerService .GetClient ()
98+ dockerClient , err := s .dockerService .GetClient (ctx )
9999 if err != nil {
100100 s .eventService .LogErrorEvent (ctx , models .EventTypeContainerError , "container" , containerID , "" , user .ID , user .Username , "0" , err , models.JSON {"action" : "restart" })
101101 return fmt .Errorf ("failed to connect to Docker: %w" , err )
@@ -119,7 +119,7 @@ func (s *ContainerService) RestartContainer(ctx context.Context, containerID str
119119}
120120
121121func (s * ContainerService ) GetContainerByID (ctx context.Context , id string ) (* container.InspectResponse , error ) {
122- dockerClient , err := s .dockerService .GetClient ()
122+ dockerClient , err := s .dockerService .GetClient (ctx )
123123 if err != nil {
124124 return nil , fmt .Errorf ("failed to connect to Docker: %w" , err )
125125 }
@@ -134,7 +134,7 @@ func (s *ContainerService) GetContainerByID(ctx context.Context, id string) (*co
134134}
135135
136136func (s * ContainerService ) DeleteContainer (ctx context.Context , containerID string , force bool , removeVolumes bool , user models.User ) error {
137- dockerClient , err := s .dockerService .GetClient ()
137+ dockerClient , err := s .dockerService .GetClient (ctx )
138138 if err != nil {
139139 s .eventService .LogErrorEvent (ctx , models .EventTypeContainerError , "container" , containerID , "" , user .ID , user .Username , "0" , err , models.JSON {"action" : "delete" , "force" : force , "removeVolumes" : removeVolumes })
140140 return fmt .Errorf ("failed to connect to Docker: %w" , err )
@@ -188,7 +188,7 @@ func (s *ContainerService) DeleteContainer(ctx context.Context, containerID stri
188188}
189189
190190func (s * ContainerService ) CreateContainer (ctx context.Context , config * container.Config , hostConfig * container.HostConfig , networkingConfig * network.NetworkingConfig , containerName string , user models.User , credentials []containerregistry.Credential ) (* container.InspectResponse , error ) {
191- dockerClient , err := s .dockerService .GetClient ()
191+ dockerClient , err := s .dockerService .GetClient (ctx )
192192 if err != nil {
193193 s .eventService .LogErrorEvent (ctx , models .EventTypeContainerError , "container" , "" , containerName , user .ID , user .Username , "0" , err , models.JSON {"action" : "create" , "image" : config .Image })
194194 return nil , fmt .Errorf ("failed to connect to Docker: %w" , err )
@@ -264,7 +264,7 @@ func (s *ContainerService) CreateContainer(ctx context.Context, config *containe
264264}
265265
266266func (s * ContainerService ) StreamStats (ctx context.Context , containerID string , statsChan chan <- any ) error {
267- dockerClient , err := s .dockerService .GetClient ()
267+ dockerClient , err := s .dockerService .GetClient (ctx )
268268 if err != nil {
269269 return fmt .Errorf ("failed to connect to Docker: %w" , err )
270270 }
@@ -302,7 +302,7 @@ func (s *ContainerService) StreamStats(ctx context.Context, containerID string,
302302}
303303
304304func (s * ContainerService ) StreamLogs (ctx context.Context , containerID string , logsChan chan <- string , follow bool , tail , since string , timestamps bool ) error {
305- dockerClient , err := s .dockerService .GetClient ()
305+ dockerClient , err := s .dockerService .GetClient (ctx )
306306 if err != nil {
307307 return fmt .Errorf ("failed to connect to Docker: %w" , err )
308308 }
@@ -437,7 +437,7 @@ func (s *ContainerService) readAllLogs(logs io.ReadCloser, logsChan chan<- strin
437437}
438438
439439func (s * ContainerService ) ListContainersPaginated (ctx context.Context , params pagination.QueryParams , includeAll bool , includeInternal bool ) ([]containertypes.Summary , pagination.Response , containertypes.StatusCounts , error ) {
440- dockerClient , err := s .dockerService .GetClient ()
440+ dockerClient , err := s .dockerService .GetClient (ctx )
441441 if err != nil {
442442 return nil , pagination.Response {}, containertypes.StatusCounts {}, fmt .Errorf ("failed to connect to Docker: %w" , err )
443443 }
@@ -622,7 +622,7 @@ func (s *ContainerService) calculateContainerStatusCounts(items []containertypes
622622
623623// CreateExec creates an exec instance in the container
624624func (s * ContainerService ) CreateExec (ctx context.Context , containerID string , cmd []string ) (string , error ) {
625- dockerClient , err := s .dockerService .GetClient ()
625+ dockerClient , err := s .dockerService .GetClient (ctx )
626626 if err != nil {
627627 return "" , fmt .Errorf ("failed to connect to Docker: %w" , err )
628628 }
@@ -675,7 +675,7 @@ func (e *ExecSession) Close(ctx context.Context) error {
675675
676676// AttachExec attaches to an exec instance and returns an ExecSession for lifecycle management.
677677func (s * ContainerService ) AttachExec (ctx context.Context , containerID , execID string ) (* ExecSession , error ) {
678- dockerClient , err := s .dockerService .GetClient ()
678+ dockerClient , err := s .dockerService .GetClient (ctx )
679679 if err != nil {
680680 return nil , fmt .Errorf ("failed to connect to Docker: %w" , err )
681681 }
0 commit comments